Jennie... some info please...
What is the name of your form?
What is the name of the field that contains the ID?
Is that field located on the Main form?
Are you leaving the form open as you run the report?
Please copy and paste your query criteria so I can check it against the
questions above.
Also, with the form open, and a legitimate ID selected, try opening the
report in Design mode and just running the RecordSource query via the
query
grid. Does the query run?
hth
Al Camp
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions
I tried your way and it does work very well but it prompts me for the ID
number. I made sure that the fields were all spelled correctly and
everything. What am I doing wrong?
:
Jennie,
Rick's solution is perfectly viable, but... perhaps you'd find my
solution a bit easier to implement. It only takes a moment to set it
up
and
try.
Just code to Open the Report on cmdPrint_Click, and the query
automatically look to your "calling" form for the filter value it
needs.
hth
Al Camp
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions
Now I am having another problem, I attached your code to the command
button
on my form, but I also have another form that I want to do the same
thing
but
with a different set of records. I copied the code but changed the
name
of
the report and I get an automation error. Any idea why?
:
You don't need to use the query. Just build a report, and modify
the
following code to meet your needs...
Private Sub cmdPrint_Click()
Dim strWhere As String
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenReport "MyReport", acViewPreview, ,
strWhere
End If
End Sub
Notes: If your primary key is a Text type field (not a Number type
field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"
If you want the report to print without preview, replace
acViewPreview
with
acViewNormal.
See also:
http://allenbrowne.com/casu-15.html
--
Rick B
I want to print the current record on a form to a preprinted
report
using
a
command button (I need to print invoices). I set up a query using
the
autonumber as a parameter, so it will only print that record. How
can I
have
it automatically print that record without prompting for
criteria?