My solution is very similar to ranman's. But since I have been working on it for a while, I will post it also.
The key is to create an unbound form, with the following text boxes:
- txtProjectID (I assumed text)
- txtWorkItems (assumed text)
- txtDescription (assumed text)
- txtStartDate (date)
- txtEndDate (date)
- txtHours (assumed number)
Then I added a command button named "cmdAddRecords".
You would also need to replace "TableName" with whatever the name of your table is.
So, here is the code behind the command button that would add all those records.
Code:
Private Sub cmdAddRecords_Click()
Dim mySQL As String
Dim myDate As Date
' Check to make sure that end date is not before start date
If Me.txtEndDate < Me.txtStartDate Then
MsgBox "Please try again!", vbOKOnly, "Invalid Date Entries!"
Else
' Loop through dates
myDate = Me.txtStartDate
Do Until myDate > Me.txtEndDate
' Build insert SQL code
mySQL = "INSERT INTO TableName ([Project ID], [Work Items], Description, [Date], Hours) "
mySQL = mySQL & "VALUES('" & Me.txtProjectID & "','" & Me.txtWorkItems & "','" & Me.txtDescription & "',#" & myDate & "#," & Me.txtHours & ")"
' Run query
'MsgBox mySQL
DoCmd.SetWarnings False
DoCmd.RunSQL mySQL
DoCmd.SetWarnings True
' Add one to date
myDate = myDate + 1
Loop
MsgBox "Done!"
End If
End Sub
You can add whatever checks and validations you might need. I just added one, to make sure that txtEndDate is not before txtStartDate.