Run a query..

  • Thread starter Thread starter Combo box type - help
  • Start date Start date
C

Combo box type - help

hi.. im really new at this access programming.. I need some help on this a i
dont what to do next..
I created a form where i have some input fields.. i have this form bound to
a table.. so those inputs are being sent to the table.. After this i created
a new form with only two fields.. the month and the year and what i want to
do is to somehow make a search for those two fields in the table.. and send
every value on the table that correspond to that month and year to a report..
I know i need to make a query but nothing else, wich kind of query, how to
program the table search, how to send the values.... can you please help me..
Many thanks..
 
1. Start out by creating your report, figure out what information you want
displayed in the report and create a query that gives you the information you
need. Once you have that working, for all the records in your table, proceed
to the next step.

2. Open your query in design view. Place your cursor in the criteria row,
in the column for year (don't use Month or Year as a field name, they are
reserved words). Enter the following in that box:

Forms!yourFormName.txt_Year

Where you replace "yourFormName" with the name of your form that has the
year and month filters, and replace "txt_Year" with the name of the control
on that form.

Do the same thing with the Month field.

Run the query. If your form is not open, it will ask you for the two
values. If it is open, and has values in the FilterYear and FilterMonth
controls, then it should generate the query with the correct values in those
fields. Save the query (I usually name mine in the format
"qry_rpt_ReportName"

3. Add two buttons to your form (the report form), Cancel and Report.

In the Cancel buttons click event, close the form.

In the Report buttons click event enter the following:

docmd.OpenReport "reportName", acViewPreview

making sure to replace "reportName" with the actual name of your report

Once you have this working the way you want, you can change acViewPreview to
acViewNormal to print the report directly to the printer.

HTH
Dale
 
Hey, exactly what i wanted..
Everything is looking good now.. i just have one more problem.. when i
search for a record (month and year) that doesnt exist yet the program brakes
and error appear.. so i think that before of this i need to make a DoCmd.find
record where i'll search for both the month and year in the table and if they
are not there i'll popup a msgbox with some error message..if so it goes to
docmd.OpenReport "reportName", acViewPreview
...
Please pay attencion to the fact that both the month and the year searched,
before opening the report need to be in the same id..in the same registration
or the program might find the month and the year but in different palces in
the table and go on to the OpenReport part followed by an error..

Many thanks!
NM

"Dale Fye" escreveu:
 
As long as the criteria in your query are both on the same line, the query
will only match those records where both the month and year match what is on
your form.

Do aleviate the "no record" problem, you can add the following as an If
statement to wrap around the docmd.openreport method:

If ISNULL(DLOOKUP("someField", "qry_rpt_ReportName")) Then
msgbox "No records match this combination!"
else
docmd.openreport "reportName", acViewPreview
end if

Change "someField" to the name of one of the fields (make sure it is one
that cannot be null) in your reports query. What this will do is check to
see if there is at least one record in the reports query. If not, it
displays a message. If so, it opens the report.

--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 
Thanks.. i understood the code you sent me.. i think is perfect.. when i
input some data not yet registered the message is poping up.. the problem is
when i input one already created.. is giving me this error "an expression you
entered is the wrong data type for one of the arguments" (error 2498).. i
cant understand what happened.. can you hel me..?
Here is the code:

Private Sub visual_Click()
If IsNull(DLookup("Mes", "Table1_Query")) Then
MsgBox "No records match this combination!"
Else
DoCmd.OpenReport Report_Report2, acViewPreview
End If
End Sub

whats wrong?
many thanks..
NM



"Dale Fye" escreveu:
 

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

Back
Top