2
votes

I am using Access VBA, and I have two forms (form1 and form2), in form 1 I have a listbox control (form1.modifiable49). I choose a list item and with a button control click I open the second form (form2),

In the second form I have some table columns, and I have a textbox where I store my variable, I would like to open form2 with the element that equals the value of modifiable49

I have:

Private Sub Form_Load()
    Me.Texte = [Forms]![Form1]![Modifiable49]
    Me.Filter = "[id_parcelle]=" & Texte
    Me.FilterOn = True
End Sub

but when I choose the value in the listbox and I excute I get error 2427:

You entered an expression that has no value.

The expression may refer to an object that has no value, such as a form, a report, or a label control.

1
You do not mention which line gets the error. Also, is the listbox entry numeric or alpha? If alphanumeric, then your filter needs to be like: Me.Filter = "[id_parcelle]='" & Me.Texte & "'", However, the biggest issue is your reference to the listbox -- it needs to reference a specific entry within the listbox: i.e. [Forms]![Form1]![Modifiable49].ItemsSelected(0). A simpler method would be to pass the value in the form open event when you click the button..Wayne G. Dunn
i have the error in this line Me.Filter = "[id_parcelle]=" & TexteYahia El Haddad
You need more quotes. Filter is a string.Fionnuala
i have the error in this line Me.Filter = "[id_parcelle]=" & Texte and my textbox contains the value ( i verified buy a messagebox and i have a value ) the listbox entry is numericYahia El Haddad
What/where is 'Texte'? I don't believe 'Texte' contains what you think it does. As a test, add the following line of code immediately before setting the filter, then paste the result back into this thread. Debug.Print "My Text: >" & Texte & "< ListBox: >" & [Forms]![Form1]![Modifiable49] & "<"Wayne G. Dunn

1 Answers

0
votes

This will not fail and will list the value of Texte for you to investigate:

Private Sub Form_Load()
    Me!Texte.Value = [Forms]![Form1]![Modifiable49].Value
    Debug.Print "Texte:", Me!Texte.Value
    Me.Filter = "[id_parcelle]=" & Me!Texte.Value & ""
    ' or, if Texte is a string:
    ' Me.Filter = "[id_parcelle]='" & Me!Texte.Value & "'"
    Me.FilterOn = Not IsNull(Me!Texte.Value) 
End Sub