robercs
10-29-2009, 03:18 PM
I am a new programmer and have been wrestling with a problem and need a little help. I am building a simple String the allows the user to search a database based on 3 parameters. The user selects the parameter they need (via coombo box) and then enters start and end dates into test boxes. Once the user hits "Generate Report" the data matching the criteria is print previewed in a simple report. The code is shown below.
When I hit the "Generate Report" button a text box pops up asking the user to Enter a Parameter Value and it defaults to Portable (one of my combo pox selections). I don't understand why this box pops up. I don't ask for a text box in the code. The date fields sort OK and the report pops up fine as well. If I actually type in the criteria "portable" it will work as needed. Where does this popup box come from???
Sub cmdGenerateReport_Click()
Dim StrWhere As String
Dim strDates As String
Dim StrDocName As String
'Dim blnTrim As Boolean
If Me.cboTestType = "Portable" Then
StrWhere = StrWhere & "[Test Type]=" & Me.cboTestType & " And "
'blnTrim = True
ElseIf Me.cboTestType = "Van" Then
StrWhere = StrWhere & "[Test Type]=" & Me.cboTestType & " And "
ElseIf Me.cboTestType = "none" Then
StrWhere = StrWhere & "[Test Type]=" & Me.cboTestType & " And "
End If
If IsNull(Me.txtStartDAte) And Me.txtStartDAte = "" Then
If Not IsNull(Me.txtEndDate) And Me.txtEndDate <> "" Then
StrWhere = StrWhere & "[finish (date)] <=" & Me.txtStartDAte & "#"
'blnTrim = False
End If
Else
If (Not IsNull(Me.txtStartDAte) And Me.txtStartDAte <> "") And (Not IsNull(Me.txtStartDAte) Or Me.txtStartDAte <> "") Then
StrWhere = StrWhere & "[Finish (date)] Between #" & Me.txtEndDate & "# AND #" & Me.txtStartDAte & "#"
'blnTrim = False
End If
'If blnTrim Then
'StrWhere = Left(StrWhere, Len(StrWhere) - 5)
'End If
StrDocName = "General Report"
DoCmd.OpenReport StrDocName, acViewPreview, , StrWhere
End If
End Sub
Thanks in advance for any help. Much appreciated!!
When I hit the "Generate Report" button a text box pops up asking the user to Enter a Parameter Value and it defaults to Portable (one of my combo pox selections). I don't understand why this box pops up. I don't ask for a text box in the code. The date fields sort OK and the report pops up fine as well. If I actually type in the criteria "portable" it will work as needed. Where does this popup box come from???
Sub cmdGenerateReport_Click()
Dim StrWhere As String
Dim strDates As String
Dim StrDocName As String
'Dim blnTrim As Boolean
If Me.cboTestType = "Portable" Then
StrWhere = StrWhere & "[Test Type]=" & Me.cboTestType & " And "
'blnTrim = True
ElseIf Me.cboTestType = "Van" Then
StrWhere = StrWhere & "[Test Type]=" & Me.cboTestType & " And "
ElseIf Me.cboTestType = "none" Then
StrWhere = StrWhere & "[Test Type]=" & Me.cboTestType & " And "
End If
If IsNull(Me.txtStartDAte) And Me.txtStartDAte = "" Then
If Not IsNull(Me.txtEndDate) And Me.txtEndDate <> "" Then
StrWhere = StrWhere & "[finish (date)] <=" & Me.txtStartDAte & "#"
'blnTrim = False
End If
Else
If (Not IsNull(Me.txtStartDAte) And Me.txtStartDAte <> "") And (Not IsNull(Me.txtStartDAte) Or Me.txtStartDAte <> "") Then
StrWhere = StrWhere & "[Finish (date)] Between #" & Me.txtEndDate & "# AND #" & Me.txtStartDAte & "#"
'blnTrim = False
End If
'If blnTrim Then
'StrWhere = Left(StrWhere, Len(StrWhere) - 5)
'End If
StrDocName = "General Report"
DoCmd.OpenReport StrDocName, acViewPreview, , StrWhere
End If
End Sub
Thanks in advance for any help. Much appreciated!!