I am using Access 2016 VBA. All code works fine, otherwise.
Public Function PopUp()
Dim strSQL As String
Dim rs As DAO.Recordset
Dim db As DAO.Database
strSQL = "SELECT PopUpReminders.*, PopUpReminders.ReminderCompletion, PopUpReminders.ReminderStartDate, PopUpReminders.Employee FROM PopUpReminders WHERE (((PopUpReminders.ReminderCompletion)=False) AND ((PopUpReminders.ReminderStartDate)<=Now() AND ((PopUpReminders.Employee)='" & Forms![Login]![txtUserName] & "'));"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
If rs.RecordCount = 0 Then
'Do Nothing
Else
If rs.RecordCount > 0 Then
Do
DoCmd.OpenForm "SFPopUpReminder"
Loop Until rs!ViewedRecord = True
End If
End If
rs.Close
Set rs = Nothing
End Function
The error that appears is (copied exactly)
MS VB Run-time error 3075: Syntax error in query expression '(((PopUpReminders.ReminderCompletion)=False) And ((PopUpReminders.ReminderStartDate)<=Now() And ((PopUpReminders.Employee)='rerdeljac'));'.
Please note, "rerdeljac" is the logintext entered into the textbox on Forms![Login]![txtUserName] and which was matched to PopUpReminders.Employee; please note also that the error message does not include the remainder of the SQL code.
(PopUpReminders.Employee) is a field on a table filled only with text, and Forms![Login]![txtUserName] is a textbox on a form intended to be filled only with text characters.
The error occurs on the Set rs = db.OpenRecordset(strSQL) line.