G
Guest
I have a form that I am using to select a field and a corresponding value
based on that field. cboboxselectvalue and cboselectfield.
cboselectvalue uses a value list as a recordsource.
cboselectfield uses a query as a record source
The cboselectfieldvalue datatype are number,date,and text IF the user
selects a number OR date datatype, opens the report,views the data, and
closes the report and then selects a text datatype a "The value you entered
isn.t valid for this field error is generated"
If the user opens the form and selects a textdatatype first and goes trough
the same process ALL cboselectvalues can be used with no problems. WHY? My
guess is that when the repor tis closed and a new value entered the report is
still holding hte filtered value used prior to closing but that is only a
guess. My code is below for the Printpreview click event:
Private Sub CmdPreviewReport_Click()
Dim Strwhere As String
Dim blCombo2 As Boolean
'As you have differing field types, a Select Case is
'what I decided to use to ensure your "string" is properly built
'This IS
'"& Me!Number & ""
''" & Me!Text & "'"
'#" & Me!Date & "#"
Select Case Me!cboSelectField
Case "Ticket ID"
Strwhere = "[TicketID] = " & Me!cboSelectValue & ""
blCombo2 = True
'Stop
Case "Contact Date"
Strwhere = "[Contactdt] = #" & Me!cboSelectValue & "#"
blCombo2 = True
'Stop
Case "Employee Name"
Strwhere = "[EmployeeName] = '" & Me!cboSelectValue & "'"
blCombo2 = True
'Stop
Case "Employee Assigned"
Strwhere = "[EmployeeAssigned] = '" & Me!cboSelectValue & "'"
blCombo2 = True
'Stop
Case "Date Resolved"
Strwhere = "[DtResolved] = # " & Me!cboSelectValue & "#"
blCombo2 = True
'Stop
Case "Status"
Strwhere = "[Status] = '" & Me!cboSelectValue & "'"
blCombo2 = True
'Stop
Case "Priority"
Strwhere = "[PriorityField] = " & Me!cboSelectValue & "'"
blCombo2 = True
Case "Ticket ID"
Strwhere = "[TicketID] = " & Me!cboSelectValue & ""
blCombo2 = True
'Stop
Case "Contact Date"
Strwhere = "[Contactdt] = #" & Me!cboSelectValue & "#"
blCombo2 = True
'Stop
'Stop
' Case "Manager"
'Strwhere = "[Manager] = '" & Me!cboSelectValue & "'"
'blCombo2 = True
Case "Report All"
Strwhere = ""
End Select
DoCmd.OpenReport "rptTickets", acPreview, , Strwhere
DoCmd.Maximize
Me.cboSelectField = ""
Me.cboSelectValue = ""
With Me
.cboSelectValue.Value = ""
.cboSelectField.Value = ""
End With
Exit_Preview_Click:
Exit Sub
End Sub
based on that field. cboboxselectvalue and cboselectfield.
cboselectvalue uses a value list as a recordsource.
cboselectfield uses a query as a record source
The cboselectfieldvalue datatype are number,date,and text IF the user
selects a number OR date datatype, opens the report,views the data, and
closes the report and then selects a text datatype a "The value you entered
isn.t valid for this field error is generated"
If the user opens the form and selects a textdatatype first and goes trough
the same process ALL cboselectvalues can be used with no problems. WHY? My
guess is that when the repor tis closed and a new value entered the report is
still holding hte filtered value used prior to closing but that is only a
guess. My code is below for the Printpreview click event:
Private Sub CmdPreviewReport_Click()
Dim Strwhere As String
Dim blCombo2 As Boolean
'As you have differing field types, a Select Case is
'what I decided to use to ensure your "string" is properly built
'This IS
'"& Me!Number & ""
''" & Me!Text & "'"
'#" & Me!Date & "#"
Select Case Me!cboSelectField
Case "Ticket ID"
Strwhere = "[TicketID] = " & Me!cboSelectValue & ""
blCombo2 = True
'Stop
Case "Contact Date"
Strwhere = "[Contactdt] = #" & Me!cboSelectValue & "#"
blCombo2 = True
'Stop
Case "Employee Name"
Strwhere = "[EmployeeName] = '" & Me!cboSelectValue & "'"
blCombo2 = True
'Stop
Case "Employee Assigned"
Strwhere = "[EmployeeAssigned] = '" & Me!cboSelectValue & "'"
blCombo2 = True
'Stop
Case "Date Resolved"
Strwhere = "[DtResolved] = # " & Me!cboSelectValue & "#"
blCombo2 = True
'Stop
Case "Status"
Strwhere = "[Status] = '" & Me!cboSelectValue & "'"
blCombo2 = True
'Stop
Case "Priority"
Strwhere = "[PriorityField] = " & Me!cboSelectValue & "'"
blCombo2 = True
Case "Ticket ID"
Strwhere = "[TicketID] = " & Me!cboSelectValue & ""
blCombo2 = True
'Stop
Case "Contact Date"
Strwhere = "[Contactdt] = #" & Me!cboSelectValue & "#"
blCombo2 = True
'Stop
'Stop
' Case "Manager"
'Strwhere = "[Manager] = '" & Me!cboSelectValue & "'"
'blCombo2 = True
Case "Report All"
Strwhere = ""
End Select
DoCmd.OpenReport "rptTickets", acPreview, , Strwhere
DoCmd.Maximize
Me.cboSelectField = ""
Me.cboSelectValue = ""
With Me
.cboSelectValue.Value = ""
.cboSelectField.Value = ""
End With
Exit_Preview_Click:
Exit Sub
End Sub