DigitalS27
Registered User.
- Local time
- Today, 16:03
- Joined
- Sep 13, 2013
- Messages
- 13
Hi guys,
I have created a small database for entering samples received and condition of the sample.
I then created a simple report and added a button on a form with a start date and end date field.
So on the form the user selects the customer from a combobox, the user can then enter a start date and end date or leave the date boxes blank. then when the user clicks show report it should show the report. However, I can't seem to get this right. when I select show report without selecting a customer from the combobox I get a messagebox " a customer needs to be entered" this is part of the code.
But then I select a customer, and then it asks me to enter the customer ID / enter parameter value for some reason. doesnt matter what customer id i enter, it gives a blank report and then access wants to debug.
Please, please assist.
Below is the code used:
:banghead::banghead:
I have created a small database for entering samples received and condition of the sample.
I then created a simple report and added a button on a form with a start date and end date field.
So on the form the user selects the customer from a combobox, the user can then enter a start date and end date or leave the date boxes blank. then when the user clicks show report it should show the report. However, I can't seem to get this right. when I select show report without selecting a customer from the combobox I get a messagebox " a customer needs to be entered" this is part of the code.
But then I select a customer, and then it asks me to enter the customer ID / enter parameter value for some reason. doesnt matter what customer id i enter, it gives a blank report and then access wants to debug.
Please, please assist.
Below is the code used:
Code:
Private Sub cmdPreview_Click()
Dim stDocName As String
Dim strWhere As String
Dim Tmp As Date
Dim dtStart As String
Dim dtEnd As String
stDocName = "SampleInformation"
If Len(Trim(Me.cboCustomer)) > 0 Then
strWhere = "[Customer_Number] = " & Me.cboCustomer & " AND "
Else
MsgBox " A customer is REQUIRED!!!"
Exit Sub
End If
'check the dates
If IsDate(Me.txtDateFrom) Then
dtStart = Me.txtDateFrom
End If
If IsDate(Me.txtDateThru) Then
dtEnd = Me.txtDateThru
End If
'create the filter string
If IsDate(dtStart) And IsDate(dtEnd) Then
If dtStart > dtEnd Then
Tmp = dtStart
dtStart = dtEnd
dtEnd = Tmp
Tmp = Empty
Me.txtDateFrom = dtStart
Me.txtDateThru = dtEnd
End If
strWhere = strWhere & "[Sample_Date] Between #" & dtStart & "# AND #" & dtEnd & "# AND "
ElseIf IsDate(dtStart) Then
' greater than date Start
strWhere = strWhere & "[Sample_Date] >= #" & dtStart & "# AND "
ElseIf IsDate(dtEnd) Then
'less than end date
strWhere = strWhere & "[Sample_Date] <= #" & dtEnd & "# AND "
End If
If Len(strWhere) > 0 Then
'remove the trailing " AND "
strWhere = Left(strWhere, Len(strWhere) - 5)
Else
strWhere = ""
End If
' Debug.Print strWhere
DoCmd.OpenReport stDocName, acPreview, , strWhere
End Sub
:banghead::banghead:
Last edited: