I am getting an error when I try to execute my query in my loop.
What I try to do is to loop through my recordset and return the value matching the ID. I have a table named Manufacturer and 2 columns named ID and Manuf.
I have commented out the 3 different execution methods, as I cannot get them to work probably.
Sub LoopExample()
On Error GoTo Error_Handler
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim iCount As Integer
Dim strSQL As String
Dim intManu As Integer
strSQL = "SELECT * FROM Manufacturer"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL) 'open the recordset for use (table, Query, SQL Statement)
Do While Not rs.EOF
intManu = rs!ID
strSQL = "SELECT Manuf FROM Manufacturer WHERE CustomerID='" & intManu & "'"
'db.Execute (strSQL), dbFailOnError
'DoCmd.OpenQuery strSQL, acViewNormal
'CurrentDb.OpenRecordset (strSQL)
Debug.Print strSQL
rs.MoveNext
Loop
rs.Close 'Close the recordset
Error_Handler_Exit:
On Error Resume Next
'Cleanup after ourselves
Set rs = Nothing
Set db = Nothing
Exit Sub
Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
Err.Number & vbCrLf & "Error Source: LoopRecExample" & vbCrLf & "Error Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Resume Error_Handler_Exit
End Sub