Good Evening,
The filter on a recordset works fine when a literal is used but when a variable containing the same value as the string literal the filter does not accept it. The code is below. Can you assist?
Option Compare Database
Private Sub Command43_Click()
Dim curDatabase As Database
Set curDatabase = CurrentDb
Dim rs3 As Recordset
Dim t As Recordset
Dim g As String
Set rs3 = curDatabase.OpenRecordset("Select * from [Courses under Programs]")
g = "ANS.CT"
rs3.Filter = "[ProgramCode]= " & g ' The problem is at this line
Set t = rs3.OpenRecordset
t.MoveLast
t.MoveFirst
MsgBox t.RecordCount
End Sub
' This code works well:
rs3.Filter = "[ProgramCode]= 'ANS.CT'"