Filter reports by combo box

B

Bobby.Dannels

I have a form with lstReports displaying all reports in my database.
cboFilter is a combo box with a list of sections (a field in all
reports). I am trying to Filter all reports by the section selected in
the cboFilter. This is the code I am using. Please help.

Private Sub chkPreview_Click()
On Error GoTo Err_chkPreview_Click

Dim stDocName As String

stDocName = Me.lstReports

If Me.cboFilter <> "" Then
DoCmd.OpenReport stDocName, acViewPreview, , "Section =
Me.cboFilter.Value"

Else
DoCmd.OpenReport stDocName, acViewPreview, selectsection
End If

Exit_chkPreview_Click:
Exit Sub

Err_chkPreview_Click:
MsgBox Err.Description
Resume Exit_chkPreview_Click

End Sub
 
M

Marshall Barton

I have a form with lstReports displaying all reports in my database.
cboFilter is a combo box with a list of sections (a field in all
reports). I am trying to Filter all reports by the section selected in
the cboFilter. This is the code I am using. Please help.

Private Sub chkPreview_Click()
On Error GoTo Err_chkPreview_Click

Dim stDocName As String

stDocName = Me.lstReports

If Me.cboFilter <> "" Then
DoCmd.OpenReport stDocName, acViewPreview, , "Section =
Me.cboFilter.Value"

Else
DoCmd.OpenReport stDocName, acViewPreview, selectsection
End If


The first OpenReport needs to pass the value of the combo
box. The way you hace it, you are passing the name of the
combo box. Presuming the Section field is a numberic type
of field. It should be:

DoCmd.OpenReport stDocName, acViewPreview, , _
"Section = " & Me.cboFilter.Value

If the Section field is a Text field, then you could use:

DoCmd.OpenReport stDocName, acViewPreview, , _
"Section = """ & Me.cboFilter.Value & """"

I can't tell for sure, but it is extremely likely that your
check for nothng in the combo box is inappropriate. If what
you have doesn't work, try using:

If Not IsNull(Me.cboFilte) Then

I have never used (never even heard of anyone else using)
the OpenReport method's Filter property so I can not comment
on your second OpenReport line.
 
B

Bobby.Dannels

Code is a text file. Thanks ... works great. Next question, is I want
my combo box to be disabled when optAll (option button) is selected,
and enabled when optSection (option button) is selected. I was told to
use the on click property, but there is not one. I don't know if it is
because I am using office 2000.
 
M

Marshall Barton

Code is a text file. Thanks ... works great. Next question, is I want
my combo box to be disabled when optAll (option button) is selected,
and enabled when optSection (option button) is selected. I was told to
use the on click property, but there is not one. I don't know if it is
because I am using office 2000.


Depends on if the option button is in an option group frame
or just a control on the form.


If it's in a frame, use the frame's AfterUpdate event:
Me.combo.Enabled = (Me.frame <> X)
where X it the optAll option button's OptionValue

If it's a stand alone option button, use the button's
AfterUpdate event:
Me.combo.Enabled = (Not Me.button)
 
B

Bobby.Dannels

So far you have solved two of my most agrivating problems. Thank you.
If you could tell me how to import and export my table to/from an xml
file, you would be my hero.

Upon importing an xml file, I would like it to add the records to my
data table.

Exporting is more complicated. As before there are two option buttons
in a group called selectSectionFor. If option button "allDatabase" is
selected (option value 1) i would like the export data button
"cmdMoveData" to export the entire database to an xml file. If option
button "SpecificSection" is selected (option value 2) i would like to
export only records from a certain section. The field name in the
"Data Table" is "Section" and the combo box "cboSelectSection"
contains text values matching the sections.
 
M

Marshall Barton

So far you have solved two of my most agrivating problems. Thank you.
If you could tell me how to import and export my table to/from an xml
file, you would be my hero.

Upon importing an xml file, I would like it to add the records to my
data table.

Exporting is more complicated. As before there are two option buttons
in a group called selectSectionFor. If option button "allDatabase" is
selected (option value 1) i would like the export data button
"cmdMoveData" to export the entire database to an xml file. If option
button "SpecificSection" is selected (option value 2) i would like to
export only records from a certain section. The field name in the
"Data Table" is "Section" and the combo box "cboSelectSection"
contains text values matching the sections.


Sorry, I have never tried to work with XML files. About all
I can say is to export a filtered set of records, create a
query that selects the desired records and export the query
as if it were a table.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top