I have 2 textboxes and a button. The button opens a query with the values of the textboxes. Everything works fine, except when one textbox is empty then I want to find all the records from that textbox(So far I've tested it on textbox2). Here is my code:
Private Sub vbaBtn_Click()
Dim af1 As String, af2 As String
af1 = "([a1]='" + [krit1] + "') "
If krit2 = "" Then
af2 = "([a2]='" + "*" + "') "
Else
af2 = "([a2]='" + [krit2] + "') "
End If
DoCmd.OpenForm "FormLisategevusalad", acFormDS, , af1 & " " & "And" & " " & af2
End Sub
It seems to me, that VBA is always choosing the Else option not the If one, since when I debugged it said the error is an "Invalid use of null" and pointed to the Else condition.
Am I using a wrong method to detect and empty string? If I get the empty string recognition to work, is this af2 = "([a2]='" + "*" + "') "
the right way to return all records?
Thanks in advance.