businesshippieRH
Registered User.
- Local time
- Today, 14:37
- Joined
- Aug 8, 2014
- Messages
- 60
I have created a loop which seems to work perfectly. The AddSQL bit prints perfectly to the intermediate window. However, the DoCmd.RunSQL doesn't seem to work, and I can't figure out why. Any help is appreciated!
Private Sub Form_Load()
'Add all new entries from Default schedule to "temporary" tbl for enty to new schedule
Private Sub Form_Load()
'Add all new entries from Default schedule to "temporary" tbl for enty to new schedule
Code:
Dim Updatetbl_RS_NEW As String
Updatetbl_RS_NEW = "INSERT INTO tbl_RateSchedule_NEW (EqTypeID, DefaultDailyRate, DefaultWeeklyRate, DefaultMonthlyRate, AddedBy, DateAdded) " & _
"SELECT EqTypeID, DailyRate, WeeklyRate, MonthlyRate, AddedBy, DateAdded " & _
"FROM tbl_RateSchedule_DEFAULT " & _
"WHERE NOT EXISTS (SELECT * FROM tbl_RateSchedule_NEW " & _
"WHERE tbl_RateSchedule_NEW.EqTypeID = tbl_RateSchedule_DEFAULT.EqTypeID)"
DoCmd.RunSQL Updatetbl_RS_NEW
'Since tbl_RS_DEFAULT doesn't have an EquipmentType Field, use loop to get each from tbl_EqTypeValidValues and Add it
Dim DBS As DAO.Database
Dim RS As DAO.Recordset
Dim FinderSQL As String
Dim IntI As Integer
'Set to look at the list created
'Find empty...
Set DBS = CurrentDb
FinderSQL = "SELECT EqTypeID FROM tbl_RateSchedule_NEW WHERE EquipmentType Is Null"
Set RS = DBS.OpenRecordset(FinderSQL, dbOpenDynaset)
'If RS Empty, quit
If RS.EOF Then Exit Sub
'Do Stuff with Equipment types without names
With RS
Do Until .EOF
'Add to table
Dim AddSQL As String
AddSQL = "INSERT INTO tbl_RateSchedule_NEW (EquipmentType) " & _
"SELECT EquipmentType " & _
"FROM tbl_EquipmentTypeValidValues " & _
"WHERE tbl_RateSchedule_NEW.EqTypeID = " & RS!EqTypeID
Debug.Print AddSQL
DoCmd.SetWarnings (WarningsOff)
DoCmd.RunSQL AddSQL
DoCmd.SetWarnings (WarningsOn)
.MoveNext
Loop
End With
'Refresh form RecordSource
Me.Requery
End Sub
Last edited: