2
votes

I have an unbound textbox in form f_FeuilleBleue. In my code, I give it a certain value;

Debug.Print strAHNS '00 0AA 00-100 F TX-01
Form_f_FeuilleBleue.txt_AHNS = strAHNS

If I put a stopping point on the next line, the immediate window shows that

?Form_f_FeuilleBleue.txt_AHNS
 answer: 00 0AA 00-100 F TX-01

However, I still see it as blank in my form. There is no data to be read!

How do I fix this? Is it an issue with screen updating? (I have nothing setting it to off) Maybe form updating? (I have a msgBox in the BeforeUpdate event but it doesn't go in that event)

EDIT - additional info:

When I open the form, there is no problem. I can change the value in the form or by code. However the issue only happens when the form is opened from a menu-style form. Code below. Even after the opening sub finishes, the textbox won't update (visually - it does in value). After testing I see that the Change and the Update event are NOT launched when changing the value of the textbox from another sub (Private subs may be the cause?) But why is it continuing to not show the values even after the subs end?

Could be very, very relevant to read but I'm not sure what to make of it: Obtaining textbox value in change event handler

Here is the code that opens the form:

Private Sub Command7_Click()
    Dim strAHNS As String
    Dim strquery As String
    strAHNS = Replace(Mid(Me.Combo_Dessin2, InStr(Me.Combo_Dessin2, "=") + 1), "=", " ")
    strquery = "[ID] = (SELECT Max([ID]) FROM [Feuilles])"
    Debug.Print strquery
    If (PremierAffichage) Then
        DoCmd.OpenForm FormName:="f_feuillebleue", WhereCondition:=strquery
    Else
        MsgBox "Le projet ou dessin n'a pas été trouvé."
    End If
End Sub

Function PremierAffichage() As Boolean
    Dim rsFeuilles As DAO.Recordset
    Dim rsProjets As DAO.Recordset
    Dim strContrat As String
    Dim strProjet As String
    Dim strDessin As String
    Dim sqlquery As String
    Dim strAHNS As String
    Dim strGroupe As String
    Dim strMachine As String

    If IsNull(Me.Combo_Dessin2) Or IsNull(Me.Combo_Projet) Or Me.Combo_Dessin2.Value = "" Then
        PremierAffichage = False
        Exit Function
    End If

    strProjet = Me.Combo_Projet
    strAHNS = Me.Combo_Dessin2
    strMachine = Mid(strAHNS, 4, 3)
    strGroupe = Mid(strAHNS, 8, 2)
    Debug.Print strProjet & " ** " & strAHNS & " ** " & strMachine & " ** " & strGroupe

    sqlquery = "SELECT [AHNS], [Contrat], [No Projet], [EP (groupe)], [Type machine], [Mois] FROM [Feuilles]" 'WHERE [AHNS] = '" & strAHNS & "'"
    Set rsFeuilles = CurrentDb.OpenRecordset(sqlquery)

    sqlquery = "SELECT [Projet HNA] FROM [Projets] WHERE [Projet AHNS] = '" & strProjet & "'"
    Set rsProjets = CurrentDb.OpenRecordset(sqlquery)

    Debug.Print strAHNS    '========================================--------
    Form_f_FeuilleBleue.txt_AHNS = strAHNS ' this works in .value but not showing the result
    DoEvents '                         any changes from there on don't update the value visually
    '                       ==========================================------
    If rsProjets.RecordCount > 0 Then
        rsFeuilles.AddNew
        rsFeuilles![Contrat] = rsProjets![Projet HNA]
        rsFeuilles![No Projet] = strProjet
        rsFeuilles![AHNS] = strAHNS
        rsFeuilles![Mois] = MonthName(Mid(Date, 6, 2))
        If strMachine Like "[A-Z][A-Z][A-Z]" Then
            rsFeuilles![Type machine] = strMachine
            rsFeuilles![EP (groupe)] = strGroupe
        End If
        rsFeuilles.Update

        PremierAffichage = True
    End If

    rsProjets.Close
    Set rsProjets = Nothing

    rsFeuilles.Close
    Set rsFeuilles = Nothing

End Function
1
Is this just in debug? Try DoEvents after the line where you set it.MatthewD
This is both in the immediate window and the actual code. DoEvents did not change anything (I just wrote DoEvents by itself on the next line, is that what you wanted to try?)David G
Yes. I have seen it solve some odd issues like this. Is Form_f_FeuilleBleue the name of your textbox? Can you set it by Form_f_FeuilleBleue.text ?MatthewD
I have never needed to use it but the form does have a repaint method. form1.repaint. See if that does anything.MatthewD
Also you can change the Update or Change event to public and call it manually after you set the value. Form_f_FeuilleBleue.txt_AHNS_ChangeMatthewD

1 Answers

1
votes

Assign your value to the active form instance (the open form) instead of to the form's class.

So assuming the open form's name is f_FeuilleBleue and you want to assign that value to the form's txt_AHNS control ...

'Form_f_FeuilleBleue.txt_AHNS = strAHNS
Forms!f_FeuilleBleue!txt_AHNS = strAHNS

Reference the form by its name as a member of the Forms collection.