G
Guest
The code below is intended to append tbl_hotel for each night a person is
staying based on their flight information from tbl_Flights.
I am trying to determine why it doesn't move to the next record, but appends
the nights for the same person over and over. I'm under the gun and would
appreciate any help you can give!
---------------------------------------------------------------------------------
Private Sub cmd_AppendHotelFromFlights_Click()
Dim mySQL, i, LenStay As String
Dim rs As DAO.Recordset
Set rs = DBEngine(0)(0).OpenRecordset("tbl_Flights")
rs.MoveLast
rs.MoveFirst
Do While Not rs.EOF
LenStay = DateDiff("d", ArriveDate, DepartDate)
'Append the first night
mySQL = "INSERT INTO tbl_Hotel ( AttendeeID, Night ) " & _
"SELECT AttendeeID AS Who, ArriveDate AS When"
DoCmd.RunSQL mySQL
'Append the remaining nights
For i = 1 To LenStay - 1
Me.txt_i = i 'Can't seem to find a way to use just i in the SQL;
this is a work-around
mySQL = "INSERT INTO tbl_Hotel ( AttendeeID, Night ) " & _
"SELECT AttendeeID AS Who, " & _
"ArriveDate +
[Forms]![frm_AppendHotel_Sub].[txt_i] AS When"
DoCmd.RunSQL mySQL
Next i
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
'Update shared information for FCEs
DoCmd.RunSQL "qry_UpdateFCERoomShare"
End Sub
staying based on their flight information from tbl_Flights.
I am trying to determine why it doesn't move to the next record, but appends
the nights for the same person over and over. I'm under the gun and would
appreciate any help you can give!
---------------------------------------------------------------------------------
Private Sub cmd_AppendHotelFromFlights_Click()
Dim mySQL, i, LenStay As String
Dim rs As DAO.Recordset
Set rs = DBEngine(0)(0).OpenRecordset("tbl_Flights")
rs.MoveLast
rs.MoveFirst
Do While Not rs.EOF
LenStay = DateDiff("d", ArriveDate, DepartDate)
'Append the first night
mySQL = "INSERT INTO tbl_Hotel ( AttendeeID, Night ) " & _
"SELECT AttendeeID AS Who, ArriveDate AS When"
DoCmd.RunSQL mySQL
'Append the remaining nights
For i = 1 To LenStay - 1
Me.txt_i = i 'Can't seem to find a way to use just i in the SQL;
this is a work-around
mySQL = "INSERT INTO tbl_Hotel ( AttendeeID, Night ) " & _
"SELECT AttendeeID AS Who, " & _
"ArriveDate +
[Forms]![frm_AppendHotel_Sub].[txt_i] AS When"
DoCmd.RunSQL mySQL
Next i
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
'Update shared information for FCEs
DoCmd.RunSQL "qry_UpdateFCERoomShare"
End Sub