Cetting A Report To Select Records Based Upon A Value Selected In A Combo Box 
Author Message
 Cetting A Report To Select Records Based Upon A Value Selected In A Combo Box

I cannot get the below VBA code in
ACCESS97 To Run.

' Purpose To Select An Item From A Combo

Drop Down Box and Then Get A Report To
Run Showing Only Those Records Which
Match The Criteria From The Combo Box.

Have tried many different varieties of
the below and cannot get it to work.

Private Sub Squizz_Click()
Dim CountryEntry As Variant
Dim MyChar As Variant
Dim MyChar2 As Variant
Dim CountrySelect As String
Dim CountryString As String
Dim CountryStringEnd As String

' MyChar = Chr(34)- Not Being Used Here
At This Stage
MyChar2 = Chr(39)

Let CountrySelect = [CountryName] '
"Country" Here Is A Combo Control On A
Form
Let CountryString = "Country = '"
Let CountryStringEnd = MyChar2

CountryEntry = CountryString &
CountrySelect & CountryStringEnd ' This
Won't Work _
' While The Below Line Works Fine
 'CountryEntry = "Country = 'MEXICO' OR
Country = 'UK'" This Works Fine

 'CountryEntry = "Country = 'UK'" This
Works Fine

DoCmd.OpenReport "RptCustomers",
acViewPreview, , CountryEntry

End Sub



Fri, 18 Jul 2003 11:21:36 GMT  
 Cetting A Report To Select Records Based Upon A Value Selected In A Combo Box
John,
Do you allways do things the hard way? Consider renaming your combo box to
cboCountry. Get rid of all the "Let" stuff and try:

Private Sub Squizz_Click()
    Dim strWhere as String
    If Not IsNull(Me.cboCountry) Then
        strWhere = "[Country] = '" & Me.cboCountry & "'"
    End If
    DoCmd.OpenReport "RptCustomers", acViewPreview, , strWhere
End Sub


Quote:
> I cannot get the below VBA code in
> ACCESS97 To Run.

> ' Purpose To Select An Item From A Combo

> Drop Down Box and Then Get A Report To
> Run Showing Only Those Records Which
> Match The Criteria From The Combo Box.

> Have tried many different varieties of
> the below and cannot get it to work.

> Private Sub Squizz_Click()
> Dim CountryEntry As Variant
> Dim MyChar As Variant
> Dim MyChar2 As Variant
> Dim CountrySelect As String
> Dim CountryString As String
> Dim CountryStringEnd As String

> ' MyChar = Chr(34)- Not Being Used Here
> At This Stage
> MyChar2 = Chr(39)

> Let CountrySelect = [CountryName] '
> "Country" Here Is A Combo Control On A
> Form
> Let CountryString = "Country = '"
> Let CountryStringEnd = MyChar2

> CountryEntry = CountryString &
> CountrySelect & CountryStringEnd ' This
> Won't Work _
> ' While The Below Line Works Fine
>  'CountryEntry = "Country = 'MEXICO' OR
> Country = 'UK'" This Works Fine

>  'CountryEntry = "Country = 'UK'" This
> Works Fine

> DoCmd.OpenReport "RptCustomers",
> acViewPreview, , CountryEntry

> End Sub



Thu, 17 Jul 2003 21:08:27 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How do I select records based on a value typed into a text box

2. selecting records for 2nd combo box dependant on first combo box

3. select records based on the selection from the dropdown combo

4. enter data in a combo box based on value from another combo box

5. default value in combo box to last selected

6. Clear the selected value of a Combo Box?

7. IMPORTANT: Read the selected Value from a Combo Box

8. selected value in a combo box

9. Using a combo box to move to selected record

10. Using Combo Box to Select Records on From

11. How to have combo box in one form select record to be used in another form

12. Using a combo box to select a record

 

 
Powered by phpBB® Forum Software