By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,477 Members | 1,641 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,477 IT Pros & Developers. It's quick & easy.

print current report

P: 14
hello educated friends

i have a question. i created a table name info. the primary key field is [maininfoID], i created a query from that table named it [info query], and a form from that query. On my form which by the way named [timesheet]i want my employees to enter data,then press the print button to print out a current report of the information that was just entered. report name is [yourcopy] i was told to use this event procedure
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "rptyourcopy",acViewPreview, , _
  2. "[maininfoID]=Forms!frmtimesheet"
i know theres more to this, can someone help me please.
Dec 29 '11 #1

✓ answered by Stewart Ross

The error message is pointing out the obvious - read your last post. Why have you got this line?

strReport = "info"

Info is NOT the correct name of your report, which you have said yourself is yourcopy. That line should surely be

strReport = "yourcopy"

or, if that too is incorrect and it is really what you posted in post #1,

strReport = "rptyourcopy"

You have to be consistent and correct in what you post!!

-Stewart

Share this Question
Share on Google+
3 Replies


Expert Mod 2.5K+
P: 2,545
It is essential that you understand what the code is doing - being 'given it' is not enough. The OpenReport action can be filtered so that instead of the report showing all records it shows just a subset of them, or in this case, the record matching the one in your form.

To do this the MainInfoID field on the report has to be matched to the corresponding value on your form - but at present (in line 2 above) you are not supplying the value of the field at all, just a reference to the form itself. You also need to include the value of the control, not a reference to its name, in the filter statement.

Assuming that the control on your form is also called maininfoID, try replacing line 2 with:

Expand|Select|Wrap|Line Numbers
  1. "[maininfoID] = " & Forms!frmtimesheet!maininfoID
or, using the simpler reference to the current form itself available using the Me keyword,

Expand|Select|Wrap|Line Numbers
  1. "[maininfoID] = " & Me!maininfoID
This assumes that your primary key is a number. If it is not a number but is instead a text string, you would need to include the value inside single quotes, like this:

Expand|Select|Wrap|Line Numbers
  1. "[maininfoID] = '" & Me!maininfoID & "'"
Please note that this last example is for text strings only - it will not work at all if the value being matched is a number, so please do not confuse the two forms of the statement!

-Stewart
Dec 29 '11 #2

P: 14
ok Mr Ross
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command151_Click()
  2. Dim strReport As String
  3. Dim strWhere As String
  4.  
  5. strReport = "info"
  6. strWhere = "[maininfoID] = """ & Me![maininfoID] & """"
  7.  
  8. DoCmd.OpenReport strReport, acViewPreview, , strWhere
  9.  
  10. End Sub
im getting a run-time error 2103, :the report name you entered incorrect but i know its correct the name is [yourcopy]
Dec 29 '11 #3

Expert Mod 2.5K+
P: 2,545
The error message is pointing out the obvious - read your last post. Why have you got this line?

strReport = "info"

Info is NOT the correct name of your report, which you have said yourself is yourcopy. That line should surely be

strReport = "yourcopy"

or, if that too is incorrect and it is really what you posted in post #1,

strReport = "rptyourcopy"

You have to be consistent and correct in what you post!!

-Stewart
Dec 29 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.