D
DJ Notion via AccessMonster.com
This question involves the following:
Tables: Print_Shipments_by_Date, UPS_SHIPPING_EB (linked)
Forms: Print_Shipments_by_Date, UPSshippingEB
Reports: Print_Shipments_by_Date
The linked table has a field called CollectionDate that is 14 digits
yyyymmddhhmmss. On the UPSshippingEB form I have an unbound text box with
the following as the control source: =Mid([CollectionDate],5,4) & "2008".
This makes the CollectionDate look like 00/00/0000. On that same form I have
a command button to Print Shipments by Date. When clicking, that opens up
the Print_Shipments_by_Date form where there are two fields, one to input a
start date and a second to input an end date. I want to be able to enter any
start and end date and print a report for the shipments with a collection
date within and including the date range entered on the form.
Before I show my code below, I have to point out that I use this very same
form with another database and it works beautifully. However, it is working
with an unbound text box that has =Date() in it.
I haven't added the code to check the collection date. That is what I need
help with. Any help is appreciated! Thanks.
Private Sub Print_OK_Click()
On Error GoTo Err_OK_Click
Dim stDocName As String
Dim stLinkCriteria As String
If IsNull(Me.Print_start_date) Or Me.Print_start_date = "" Then
MsgBox "Please enter a Start Date.", vbOKOnly, "Required Data!"
Me.Print_start_date.SetFocus
End If
If IsNull(Me.Print_end_date) Or Me.Print_end_date = "" Then
MsgBox "Please enter an End Date.", vbOKOnly, "Required Data!"
Me.Print_end_date.SetFocus
End If
If Me.Print_start_date < #1/1/2008# Then
MsgBox "Please enter a valid Start Date.", vbOKOnly, "Invalid Entry!"
Me.Print_start_date.SetFocus
End If
If Me.Print_end_date < Me.Print_start_date Then
MsgBox "The End Date cannot be before the Start Date.", vbOKOnly,
"Invalid Entry!"
Me.Print_end_date.SetFocus
End If
If Me.Print_start_date >= #1/1/2008# And Me.Print_end_date >= Me.
Print_start_date Then
stDocName = "Print_Shipments_by_Date"
DoCmd.OpenReport stDocName, , , stLinkCriteria
DoCmd.Close acForm, "Print_Shipments_by_Date", acSaveNo
DoCmd.OpenForm "UPSshippingEB", acNormal, , , , , True
End If
Exit_OK_Click:
Exit Sub
Err_OK_Click:
MsgBox Err.Description
Resume Exit_OK_Click
End Sub
Private Sub Print_start_date_AfterUpdate()
If Me.Print_start_date < #1/1/2008# Then
MsgBox "Please enter a valid Start Date.", vbOKOnly, "Invalid Entry!"
Me.Print_start_date.SetFocus
End If
End Sub
-Jonathan
Tables: Print_Shipments_by_Date, UPS_SHIPPING_EB (linked)
Forms: Print_Shipments_by_Date, UPSshippingEB
Reports: Print_Shipments_by_Date
The linked table has a field called CollectionDate that is 14 digits
yyyymmddhhmmss. On the UPSshippingEB form I have an unbound text box with
the following as the control source: =Mid([CollectionDate],5,4) & "2008".
This makes the CollectionDate look like 00/00/0000. On that same form I have
a command button to Print Shipments by Date. When clicking, that opens up
the Print_Shipments_by_Date form where there are two fields, one to input a
start date and a second to input an end date. I want to be able to enter any
start and end date and print a report for the shipments with a collection
date within and including the date range entered on the form.
Before I show my code below, I have to point out that I use this very same
form with another database and it works beautifully. However, it is working
with an unbound text box that has =Date() in it.
I haven't added the code to check the collection date. That is what I need
help with. Any help is appreciated! Thanks.
Private Sub Print_OK_Click()
On Error GoTo Err_OK_Click
Dim stDocName As String
Dim stLinkCriteria As String
If IsNull(Me.Print_start_date) Or Me.Print_start_date = "" Then
MsgBox "Please enter a Start Date.", vbOKOnly, "Required Data!"
Me.Print_start_date.SetFocus
End If
If IsNull(Me.Print_end_date) Or Me.Print_end_date = "" Then
MsgBox "Please enter an End Date.", vbOKOnly, "Required Data!"
Me.Print_end_date.SetFocus
End If
If Me.Print_start_date < #1/1/2008# Then
MsgBox "Please enter a valid Start Date.", vbOKOnly, "Invalid Entry!"
Me.Print_start_date.SetFocus
End If
If Me.Print_end_date < Me.Print_start_date Then
MsgBox "The End Date cannot be before the Start Date.", vbOKOnly,
"Invalid Entry!"
Me.Print_end_date.SetFocus
End If
If Me.Print_start_date >= #1/1/2008# And Me.Print_end_date >= Me.
Print_start_date Then
stDocName = "Print_Shipments_by_Date"
DoCmd.OpenReport stDocName, , , stLinkCriteria
DoCmd.Close acForm, "Print_Shipments_by_Date", acSaveNo
DoCmd.OpenForm "UPSshippingEB", acNormal, , , , , True
End If
Exit_OK_Click:
Exit Sub
Err_OK_Click:
MsgBox Err.Description
Resume Exit_OK_Click
End Sub
Private Sub Print_start_date_AfterUpdate()
If Me.Print_start_date < #1/1/2008# Then
MsgBox "Please enter a valid Start Date.", vbOKOnly, "Invalid Entry!"
Me.Print_start_date.SetFocus
End If
End Sub
-Jonathan