Hi, i have a query to search a form input value for a specific username. i am using the Like * function to select all if no username has been entered or if one is entered then it passes that into the sql query string instead. the problem with this is that the LIKE function doesnt return empty fields, only the fields with data in them. is there a way around this?? so it displays empty username records aswell as ones with the same username. code is below i am using, it must be able to fit in the null check and insert into the sql string. thanks
Private Sub bob_Click()
On Error GoTo Err_bob_Click
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strsql As String
Dim strUserSearch As String
Set db = CurrentDb
Set qdf = db.QueryDefs("fullSearch")
If IsNull(Me.userSearch.value) Then
strUserSearch = " Like '*' "
Else
strUserSearch = "='" & Me.userSearch.value & "' "
End If
strsql = "SELECT dbo_HistoricalReport.*" & _
"FROM dbo_HistoricalReport " & _
"WHERE dbo_HistoricalReport.UserName" & strUserSearch & _
";"
MsgBox strsql
qdf.SQL = strsql
DoCmd.OpenQuery "fullSearch"
Set qdf = Nothing
Set db = Nothing
Exit_bob_Click:
Exit Sub
Err_bob_Click:
MsgBox Err.Description
Resume Exit_bob_Click
End Sub