G
Guest
I have the following module that I want to execute a sql statement but I
can't get the syntax to work.
Public Sub Test()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("_QryMatchedUWList")
Do Until rst.EOF
DoCmd.RunSQL
"INSERT INTO TblPickedSample ( Underwriter_ID,
Mortgage_Loan_No___10_Character)" & _
"SELECT TOP 4 tblMatchedVolume.Underwriter_ID,
tblMatchedVolume.Mortgage_Loan_No___10_Character," & _
"FROM tblMatchedVolume" & _
"WHERE (((tblMatchedVolume.Underwriter_ID)=" & "'" & rst!UnderwriterID & "'"
& "));"
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
End Sub
I am using Access 2002 and this is for a local DB not SQL Server.
The end goal is to select four records from TblMatchedVolume for each
Underwriter_ID. THe SQL statement runs as a query but I can only make it
work if the Underwriter_ID is entered via a prompt. I have nearly 300
Underwriter_ID's and I want to avoid running the query 300 times.
Any ideas on how to fix the module or a better way to go about this?
Thanks.
can't get the syntax to work.
Public Sub Test()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("_QryMatchedUWList")
Do Until rst.EOF
DoCmd.RunSQL
"INSERT INTO TblPickedSample ( Underwriter_ID,
Mortgage_Loan_No___10_Character)" & _
"SELECT TOP 4 tblMatchedVolume.Underwriter_ID,
tblMatchedVolume.Mortgage_Loan_No___10_Character," & _
"FROM tblMatchedVolume" & _
"WHERE (((tblMatchedVolume.Underwriter_ID)=" & "'" & rst!UnderwriterID & "'"
& "));"
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
End Sub
I am using Access 2002 and this is for a local DB not SQL Server.
The end goal is to select four records from TblMatchedVolume for each
Underwriter_ID. THe SQL statement runs as a query but I can only make it
work if the Underwriter_ID is entered via a prompt. I have nearly 300
Underwriter_ID's and I want to avoid running the query 300 times.
Any ideas on how to fix the module or a better way to go about this?
Thanks.