ThomasLafferty
Instructor
Hello Gurus!
Here's the scenario...
I need to insert a block of dates into a table called Driver Paperwork using the click event of an unbound form called frmInsertPaperworkDates. The dates to be inserted are entered by the user in two unbound textboxes:
txtboxBegDate
txtboxEndDate
The event I plan to use to insert the dates into my table is the click event named of a command button named btn_OK_Close_frmInsertPaperworkDates
Here's my code so far which correctly gives the dates to use and the number of dates to insert and displays them in a message box:
My plan for inserting the dates is to use a nested For Next loop somewhere in my code shown above. I will probably do something like this:
The output to my table should look something like this:
Here's where it gets a bit hairy. The numbers in the Driver field are not sequential and will not always be the ones shown above. In fact, I plan to specify criteria on my unbound form about which ones will be chosen, and the criteria resides in a related table: Driver Information which is related to Driver Paperwork by a one-to-many:
[Driver Information].[DriverID] = [Driver Paperwork].[Driver]
Here's what I don't yet know how to do:
1. How do I determine the total number of times for the Outer Loop which I will use to vary the Driver number? Run a query and count the records? If so, how do I do this without showing the resulting datasheet?
2. How do I vary the non-sequential driver number? Read the numbers into an array of some kind first?
3. How do I feed this information to my SQL string variable so I can use it to run an append query?
4. How do I check to see if the specified dates already exist for the Driver numbers chosen to prevent bloating the database?
5. How do I prevent the user from specifying a start date later than the end date?
Sorry about the long-winded post, I just want to be thorough.
Tom
Here's the scenario...
I need to insert a block of dates into a table called Driver Paperwork using the click event of an unbound form called frmInsertPaperworkDates. The dates to be inserted are entered by the user in two unbound textboxes:
txtboxBegDate
txtboxEndDate
The event I plan to use to insert the dates into my table is the click event named of a command button named btn_OK_Close_frmInsertPaperworkDates
Here's my code so far which correctly gives the dates to use and the number of dates to insert and displays them in a message box:
Code:
[COLOR=blue]Option Compare Database
Dim[/color] intJobTitle [COLOR=blue]As Integer
Dim [/color]dtStDate
[COLOR=blue]Dim [/color]dtEnDate
[COLOR=blue]Dim [/color]intDateInterval
[COLOR=blue]Dim [/color]SQL [COLOR=blue]As String[/color]
[COLOR=blue]Private Sub[/color] btn_OK_Close_frmInsertPaperworkDates_Click()
[COLOR=blue]On Error GoTo[/color] Err_btn_OK_Close_frmInsertPaperworkDates_Click
[COLOR=green]'set variables for dates to feed to SQL string[/color]
dtStDate = Me.txtboxBegDate.Value
dtEnDate = Me.txtboxEndDate.Value
intDateInterval = DateDiff("d", dtStDate, dtEnDate)
MsgBox "You have chosen the following:" _
& Chr$(13) & "Start Date: " & dtStDate _
& Chr$(13) & "End Date: " & dtEnDate _
& Chr$(13) & "Total days: " & intDateInterval, _
vbInformation, "Dates to insert"
[COLOR=green]'DoCmd.Close[/color]
Exit_btn_OK_Close_frmInsertPaperworkDate:
[COLOR=blue]Exit Sub[/color]
Err_btn_OK_Close_frmInsertPaperworkDates_Click:
MsgBox Err.Description
[COLOR=blue]Resume[/color] Exit_btn_OK_Close_frmInsertPaperworkDate
[COLOR=blue]End Sub[/color]
My plan for inserting the dates is to use a nested For Next loop somewhere in my code shown above. I will probably do something like this:
Code:
[COLOR=green]'*****Outer Loop will go here for varying driver number*****
'*****Inner Loop to generate sequential dates*****[/color]
[COLOR=blue] For [/color]dteDatesToInsert = 1 [COLOR=blue]To[/color] intDateInterval
dtStDate = dtStDate + 1 [COLOR=green]'increase by 1 day each time loop executes[/color]
[COLOR=blue]Next[/color] intDateInterval
[COLOR=green]'*****End Outer Loop will go here*****[/color]
The output to my table should look something like this:
Code:
Driver Date
23 4/1/2006
19 4/1/2006
22 4/1/2006
23 4/2/2006
19 4/2/2006
22 4/2/2006
Here's where it gets a bit hairy. The numbers in the Driver field are not sequential and will not always be the ones shown above. In fact, I plan to specify criteria on my unbound form about which ones will be chosen, and the criteria resides in a related table: Driver Information which is related to Driver Paperwork by a one-to-many:
[Driver Information].[DriverID] = [Driver Paperwork].[Driver]
Here's what I don't yet know how to do:
1. How do I determine the total number of times for the Outer Loop which I will use to vary the Driver number? Run a query and count the records? If so, how do I do this without showing the resulting datasheet?
2. How do I vary the non-sequential driver number? Read the numbers into an array of some kind first?
3. How do I feed this information to my SQL string variable so I can use it to run an append query?
4. How do I check to see if the specified dates already exist for the Driver numbers chosen to prevent bloating the database?
5. How do I prevent the user from specifying a start date later than the end date?
Sorry about the long-winded post, I just want to be thorough.
Tom