Printing report from a form, what's going wrong


B

Brewtzaff

Hi,
I'm trying to printout a report out of a form, but everytime I try to
print only the shown record, MSA opens a popup window asking me to
enter the ID, (which should be the primary key). Whatever I put in,
except 1 shows the report with an #error. But if I put in 1, all the
records are shown on the report (one/report)

Here's my code, so can someone help me please:

Private Sub CarteMembre_Click()
On Error GoTo Err_CarteMembre_Click

Dim stDocName As String
Dim strWhere As String
stDocName = "lbCartes"
strWhere = "ID= " & Me!ID
DoCmd.OpenReport stDocName, acPreview, , strWhere

Exit_CarteMembre_Click:
Exit Sub

Err_CarteMembre_Click:
MsgBox Err.Description
Resume Exit_CarteMembre_Click

End Sub

I googled a lot, but none of the answers found could resolve my
problem.

Cheers
brewtzaff
 
Ad

Advertisements

A

Allen Browne

Your report is based on a table or query.
That table/query does not contain a field named "ID".
So, when you try to open the report filtered to the ID number in your form,
Access discoverers there is no field named ID, and decides to ask you for
this value.

To solve the problemm, discover what the field name actually is, or add the
ID field to the source query.
 
B

Brewtzaff

Thx Allen,
I just logged in again to write that I found the error, and I saw your
answer.

You pointed out the exact problem, I found it out as I tried to add the
ID field in my report, as it didn't show up in the list, I understood
my problem.

Now, what's best, keep the report based on the query, or changing it to
the whole tbl or something else.

Thx again
Brewtzaff
 
A

Allen Browne

Adding the field to the query the report is based on should solve the
problem.
 
Ad

Advertisements


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