Hey guys,
I'm trying to run the module below, but this whole "SQL in VBA" thing is pretty foreign to me. Basically, I have a query that I need to run using a variable (TrNum). Rather than have the user manually change the variable and run the query, I have the TrNum in a table that the user populates via multi-select list box. Whatever the user selects is added to a temporary table (tblCriteria) to be passed through the query, into tblOutput. I keep getting the error that there is a missing operator for one, and for two...can this query be executed using the TrNum string I have put in there?
I'm trying to run the module below, but this whole "SQL in VBA" thing is pretty foreign to me. Basically, I have a query that I need to run using a variable (TrNum). Rather than have the user manually change the variable and run the query, I have the TrNum in a table that the user populates via multi-select list box. Whatever the user selects is added to a temporary table (tblCriteria) to be passed through the query, into tblOutput. I keep getting the error that there is a missing operator for one, and for two...can this query be executed using the TrNum string I have put in there?
Code:
Option Compare Database
Option Explicit
Public Function SelecTran()
Dim TrNum As String
Dim StrSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim ro As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblCriteria")
Set ro = db.OpenRecordset("tblOutput")
[B]TrNum [/B]= rs!TranCode
Do Until rs.EOF
StrSQL = "INSERT INTO tblCriteria ( AccountNumb, PacketNumb, AppliedDte, TranCode, EffctDate, TransactionName, Opeid, Amt1, Amt2, RefDate, Amt3FromDate, ToDate, Account2TraceNBR, CodesASTC, ProcCode, BatchNbr )" & _
"SELECT tblResults.AccountNumb, tblResults.PacketNumb, tblResults.AppliedDte, tblResults.TranCode, tblResults.EffctDate, tblResults.TransactionName, tblResults.Opeid, tblResults.Amt1, tblResults.Amt2, tblResults.RefDate, tblResults.Amt3FromDate, tblResults.ToDate, tblResults.Account2TraceNBR, tblResults.CodesASTC, tblResults.ProcCode, tblResults.BatchNbr" & _
"FROM tblResults" & _
"WHERE (((tblResults.TranCode)= [B]TrNum[/B]));"
DoCmd.RunSQL StrSQL
Loop
End Function