Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Boxes

Status
Not open for further replies.

Ammodog

Technical User
Dec 13, 2002
97
US
Can anyone give me a detailed description on how to Generate a report from a Query that is parametered by a Combo box in a Form. Thank You [Afro] Christopher Abney
"There is no limit to the good you can do if you dont care who gets the credit"
[Afro]
 
You don't need a parameter query. Just reference the form field in the criteria property of the query (i.e. Forms!YourFormName!YourComboBox). Here's what the SQL view of the query would look like.

SELECT * FROM YourTable WHERE (YourField=[Forms]![YourFormName]![YourComboBox]);

If you're going to build your SQL statement via code, then it should look like this:

Dim strSQL as String

strSQL = "SELECT * FROM YourTable WHERE (YourField=" & [Forms]![YourFormName]![YourComboBox] & ");"
 
Another way to do this is to assign the contents of the combo box to the form's filter then pass the filter to the report.

Private Sub cboChoice_Click()
On Error GoTo NoChoice
Dim sHold As String
sHold = Me![cboChoice]
Me.Filter = "((qryYouUse.FieldName = '" & sHold & "'))"
Me.FilterOn = True
Exit Sub

NoChoice:
If Me![cboChoice] = Null Then Exit Sub
End Sub

Private Sub cmdOpenReport_Click()
If Me.FilterOn = False Then
Me.Filter = "" 'makes sure the filter is empty if the filter is not on
DoCmd.OpenReport "rptWhatever", acViewPreview
Else: DoCmd.OpenReport "rptWhatever", acViewPreview, , Me.Filter
End If
End Sub

Hope this helps. There are lots of ways to each action.
L

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top