L
laavista
I'm new to VBA. I want to loop through two tables. This seems like an easy
task?? I can loop through the first db, but when I try to nest the 2nd one, I
get an error "object variable or with block variable not set". I've spent
hours looking through this forum, plus looking at Access "help"...
Your help would be GREATLY appreciated.
Dim dbHK As Database
Dim dbReserv As Database
Dim rstCurrecHK As DAO.Recordset
Dim rstCurrecReserv As DAO.Recordset
Dim longintHKNum As Long
Dim strConfirmNum As String
Dim longintTripsReservID As Long
Dim strSQL As String
private Sub ShuffleHKT()
Set rstCurrecHK = dbHK.OpenRecordset("SELECT t_Housekeeping.HKNum,
t_Housekeeping.ExpirationDate, t_Housekeeping.Obtained_Method,
t_Housekeeping.Used_On_Reservation " & vbCrLf & _
"FROM t_Housekeeping " & vbCrLf & _
"WHERE (((t_Housekeeping.ExpirationDate)>Date())) " & vbCrLf & _
"ORDER BY t_Housekeeping.ExpirationDate;", dbOpenDynaset)
rstCurrecHK.MoveFirst
Set rstCurrecReserv = dbReserv.OpenRecordset("SELECT
t_TripsReserv.TripsReservID, t_TripsReserv.ResortID, t_TripsReserv.[Start
date], t_TripsReserv.HKNum, t_TripsReserv.ConfirmNum, t_TripsReserv.Credits "
& vbCrLf & _
"FROM t_TripsReserv " & vbCrLf & _
"WHERE (((t_TripsReserv.[Start date])>=Date()) AND ((t_TripsReserv.Credits)
Is Not Null)) " & vbCrLf & _
"ORDER BY t_TripsReserv.[Start date];", dbOpenDynaset)
rstCurrecReserv.MoveFirst
Do Until rstCurrecHK.EOF
longintHKNum = rstCurrecHK!HKNum
MsgBox "HKNum " & longintHKNum
Do Until rstCurrecReserv.EOF
longintTripsReservID = rstCurrecReserv!TripsReservID
MsgBox "TripsReservID " & longintTripsReservID
rstCurrecReserv.MoveNext
Loop
rstCurrecHK.MoveNext
Loop
Exit Sub
task?? I can loop through the first db, but when I try to nest the 2nd one, I
get an error "object variable or with block variable not set". I've spent
hours looking through this forum, plus looking at Access "help"...
Your help would be GREATLY appreciated.
Dim dbHK As Database
Dim dbReserv As Database
Dim rstCurrecHK As DAO.Recordset
Dim rstCurrecReserv As DAO.Recordset
Dim longintHKNum As Long
Dim strConfirmNum As String
Dim longintTripsReservID As Long
Dim strSQL As String
private Sub ShuffleHKT()
Set rstCurrecHK = dbHK.OpenRecordset("SELECT t_Housekeeping.HKNum,
t_Housekeeping.ExpirationDate, t_Housekeeping.Obtained_Method,
t_Housekeeping.Used_On_Reservation " & vbCrLf & _
"FROM t_Housekeeping " & vbCrLf & _
"WHERE (((t_Housekeeping.ExpirationDate)>Date())) " & vbCrLf & _
"ORDER BY t_Housekeeping.ExpirationDate;", dbOpenDynaset)
rstCurrecHK.MoveFirst
Set rstCurrecReserv = dbReserv.OpenRecordset("SELECT
t_TripsReserv.TripsReservID, t_TripsReserv.ResortID, t_TripsReserv.[Start
date], t_TripsReserv.HKNum, t_TripsReserv.ConfirmNum, t_TripsReserv.Credits "
& vbCrLf & _
"FROM t_TripsReserv " & vbCrLf & _
"WHERE (((t_TripsReserv.[Start date])>=Date()) AND ((t_TripsReserv.Credits)
Is Not Null)) " & vbCrLf & _
"ORDER BY t_TripsReserv.[Start date];", dbOpenDynaset)
rstCurrecReserv.MoveFirst
Do Until rstCurrecHK.EOF
longintHKNum = rstCurrecHK!HKNum
MsgBox "HKNum " & longintHKNum
Do Until rstCurrecReserv.EOF
longintTripsReservID = rstCurrecReserv!TripsReservID
MsgBox "TripsReservID " & longintTripsReservID
rstCurrecReserv.MoveNext
Loop
rstCurrecHK.MoveNext
Loop
Exit Sub