Command button

G

Guest

Hello,
I have a contact database. I created a form to use as a dialog box. On the
dialog box I added 2 combo boxes which looks up information in 2 tables. The
information would be "country" and "protocol". I created a query and added
the combo boxes as criteria in the country and protocol fields. When I choose
which country and which protocol on the dialog form and click the ok button
it runs the query and filters the form. I want to create a mailing labels
report so that when I click a command button on this form, the report only
creates labels for the filtered data. My first question is: Should I base the
report on the query. My second question: Could you help me with the code for
the command button that would run the labels for the filtered data. I don't
know how to write the code myself and would appeciate any help. Could you
direct me to a link that might explain this procedure. I am using Access 2003.

Thanks in advance for any help.

Best regards,

Dee
 
G

Guest

Dee said:
Hello,
I have a contact database. I created a form to use as a dialog box. On the
dialog box I added 2 combo boxes which looks up information in 2 tables. The
information would be "country" and "protocol". I created a query and added
the combo boxes as criteria in the country and protocol fields. When I choose
which country and which protocol on the dialog form and click the ok button
it runs the query and filters the form. I want to create a mailing labels
report so that when I click a command button on this form, the report only
creates labels for the filtered data. My first question is: Should I base the
report on the query. My second question: Could you help me with the code for
the command button that would run the labels for the filtered data. I don't
know how to write the code myself and would appeciate any help. Could you
direct me to a link that might explain this procedure. I am using Access 2003.

Thanks in advance for any help.

Best regards,

Dee
 
G

Guest

(Sorry about the blank post - IE bombed on me!)

You should build a query for the report (you can either save it or simply
enter the SQL into the report's record source). If the report is the only
object in your database utilizing the query, then simply apply criteria in
the query which references the two form fields.

Otherwise, if you might use this query for other things and do not want to
hard-code criteria in the query, you can apply a filter to the VBA which
opens the report in the command button's OnClick property. Here is that
sequence (using cboCountry and cboProtocol for the form fields, and Country
and Protocol as the query field names):

DoCmd.OpenReport "ReportName", acViewPreview, , "(([Country])= '"
Forms!MyForm.cboCountry & "' AND ([Protocol])= '" & Forms!MyForm.cboProtocol
& "')"

Note that there are single quotation marks involved before/after the double
quotes. If your combo boxes are text, you will need these. If you have
numeric id's for your combo boxes (as the bound column), then you do not need
the single quotes.

HTH
 

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