I have a problem with VBA Access because I don't know the syntax. I have function which shall read fields from a table "IC4_MMI_405" correctly imported on ACCESS from an excel file:
Dim conn As New ADODB.Connection
Dim record As New ADODB.Recordset
Set conn = CurrentProject.Connection
Set record = New ADODB.Recordset
record.Open "SELECT * WHERE file = '" & sFile & "' And ccu_code = " & iCode, conn, adOpenKeyset, adLockOptimistic
with this code everything works fine. If I change the code in this way:
Dim conn As New ADODB.Connection
Dim record As New ADODB.Recordset
Dim sSQL As String
Set conn = CurrentProject.Connection
Set record = New ADODB.Recordset
sSQL = "SELECT * FROM IC4_MMI_410 WHERE file = "
sSQL = sSQL & "" & sFile & ""
sSQL = sSQL & " And ccu_code = " & iCode
record.Open sSQL, conn, adOpenKeyset, adLockOptimistic
I will receive the run time error. sFile is as String and iCode is an Integer. When I run in debug mode I can see the values of sFile and iCode are the expected ones. I think the problem lays on the way I wrote sSQL. Can you help me please?