I am trying to run SQL statment with variable in VB Access. I get error for syntax issue. I think I am missing ' or " in the statement, but I am not sure what to do.
Here is the code.
If (rs.RecordCount <> 0) Then
rs.MoveFirst
Do While rs.EOF = False
TempExportCount = TempExportCount + 1
Checkdatacsv = rs![FileName68]
OriginalFileName = rs![FileName]
'***
'This is the variable - batch number
'***
BatchNO = rs![BatchNumber]
FullPath = DirectoryPath & Checkdatacsv
DoCmd.TransferText acImportDelim, "AP-csv-Import", "tblAP_Payable_2", FullPath, False
Dim SQL2 As String
'***
'This is the statement
'***
SQL2 = "UPDATE tblAP_Payable_2 SET tblAP_Payable_2.BNO = " & BatchNO & "WHERE tblAP_Payable_2.BNO = 0;"
DoCmd.RunSQL SQL2
DoCmd.OpenQuery "qDEL_AP_BLank", acViewNormal, acEdit
When each line from csv files are imported, BatchNO is populated in the table so I will know each record is imported from which file