0
votes

I'm having trouble getting the following report to run. I keep getting the run-time error 3075.The reportText is the text box field on the form. The error seems to be in the reportsearch field.

Private Sub Command284_Click()

Dim reportsearch As String Dim reportText As String

If IsNull(Me.txtReport.Value) Then MsgBox "This box must contin a keyword" Me.txtReport.SetFocus

Else reportText = Me.txtReport.Value

reportsearch = "SELECT * FROM NCECBVI WHERE ([Last Name] LIKE """ & reportText & """ OR ([First Name] LIKE """ & reportText & """))"

DoCmd.OpenReport "NCECBVI-Report", acPreview, , reportsearch

End If

End Sub

1

1 Answers

0
votes

The WhereCondition parameter of the OpenReport command should just contain the condition itself with no other syntax around it. Change your reportsearch assignment to:

reportsearch = "[Last Name] LIKE """ & reportText & """ OR [First Name] LIKE """ & reportText & """"

Also, you are using LIKE in the condition, but you don't have any wildcard characters. Either change LIKE to = or use wildcards to get matches that contain the entered string:

reportsearch = "[Last Name] LIKE ""*" & reportText & "*"" OR [First Name] LIKE ""*" & reportText & "*"""