Printing current record on a report from a form

  • Thread starter Thread starter Snedden
  • Start date Start date
S

Snedden

I am trying to print the information from a current form to a report. I have
searched the web and tried using the different suggestions of code which,
begins with DoCmd.Open Report...but when I use that I am getting a message
that says this Macro has not been set up and I was under the impression that
I did not need a Macro...maybe I am putting this in the wrong place. I have
put the code below that I am using in the Properties of the button on the
form...on the "on click"...Please Help Me!

DoCmd.OpenReport "PrintCustomerReport",acViewPreview,, "[OrderID]=Forms!
frmEditOrder!OrderID"

Just so you know I have tried many variations of this string and all have
been wrong and ask for the Macro to be set up.

Thank you!

Snedden
 
I take it you are typing that directly in the On Click event property of
some command button.

Instead, choose [Event Procedure] in the dropdown in that property, and then
click on the build button (...) to the right.

In the VBA window that opens you'll see
Private Sub ButtonName_Click()

End Sub

Put your statement between these two lines; Then Debug menu, compile and
then hit the save button. Close the window and test it out.
 
Set the button's On Click property to:
[Event Procedure]

Then click the Build button (...) beside the property.
Access opens the code window.
Put the code in between the Private Sub... and End Sub lines.

BTW, the code works better of you concatenate the value into the criteria
string, i.e.:
DoCmd.OpenReport "PrintCustomerReport",acViewPreview, , _
"[OrderID] = " & Forms!frmEditOrder!OrderID

More details in:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html
 
Thank you so much for your assistance! I did these things that you both
suggest and I now get the report however it is for all records...it doesn't
just pull the current record that is on screen...what else can I do to fix
this.

Thanks Again for all your help!

Allen said:
Set the button's On Click property to:
[Event Procedure]

Then click the Build button (...) beside the property.
Access opens the code window.
Put the code in between the Private Sub... and End Sub lines.

BTW, the code works better of you concatenate the value into the criteria
string, i.e.:
DoCmd.OpenReport "PrintCustomerReport",acViewPreview, , _
"[OrderID] = " & Forms!frmEditOrder!OrderID

More details in:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html
I am trying to print the information from a current form to a report. I
have
[quoted text clipped - 16 lines]
 
It is now telling me that it can't find the form 'frmEditOrder' but I double-
checked the spelling to ensure it was correct and it was so not sure what is
wrong. I know this will be worth it when I get it right.

Thanks!

Allen said:
Set the button's On Click property to:
[Event Procedure]

Then click the Build button (...) beside the property.
Access opens the code window.
Put the code in between the Private Sub... and End Sub lines.

BTW, the code works better of you concatenate the value into the criteria
string, i.e.:
DoCmd.OpenReport "PrintCustomerReport",acViewPreview, , _
"[OrderID] = " & Forms!frmEditOrder!OrderID

More details in:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html
I am trying to print the information from a current form to a report. I
have
[quoted text clipped - 16 lines]
 
It you are opening the report from the frmEditOrder form, then you can
change your code to
DoCmd.OpenReport "PrintCustomerReport",acViewPreview, , _
"[OrderID] = " & Me!OrderID

Another suggestion; since you may have edits on the form you need to ensure
a save before opening the report:
If Me.Dirty Then Me.Dirty = False
DoCmd.OpenReport "PrintCustomerReport",acViewPreview, , _
"[OrderID] = " & Me!OrderID

If your command button isn't on the frmEditOrder form, then where is it?

--
Joan Wild
Microsoft Access MVP
Snedden via AccessMonster.com said:
It is now telling me that it can't find the form 'frmEditOrder' but I
double-
checked the spelling to ensure it was correct and it was so not sure what
is
wrong. I know this will be worth it when I get it right.

Thanks!

Allen said:
Set the button's On Click property to:
[Event Procedure]

Then click the Build button (...) beside the property.
Access opens the code window.
Put the code in between the Private Sub... and End Sub lines.

BTW, the code works better of you concatenate the value into the criteria
string, i.e.:
DoCmd.OpenReport "PrintCustomerReport",acViewPreview, , _
"[OrderID] = " & Forms!frmEditOrder!OrderID

More details in:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html
I am trying to print the information from a current form to a report. I
have
[quoted text clipped - 16 lines]
 
Is the form open?

Is the button on this form?

Is there a text box named OrderID on the form?

Does the code compile without error (Compile on Debug menu, in the code
window)?

What error number and exactly what message are you seeing, and which line
gives this error?

As you probably realize, code is really pedantic.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Snedden via AccessMonster.com said:
It is now telling me that it can't find the form 'frmEditOrder' but I
double-
checked the spelling to ensure it was correct and it was so not sure what
is
wrong. I know this will be worth it when I get it right.

Thanks!

Allen said:
Set the button's On Click property to:
[Event Procedure]

Then click the Build button (...) beside the property.
Access opens the code window.
Put the code in between the Private Sub... and End Sub lines.

BTW, the code works better of you concatenate the value into the criteria
string, i.e.:
DoCmd.OpenReport "PrintCustomerReport",acViewPreview, , _
"[OrderID] = " & Forms!frmEditOrder!OrderID

More details in:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html
I am trying to print the information from a current form to a report. I
have
[quoted text clipped - 16 lines]
 
Make sure the report is not already open at the time (even in design view.)

The filter is not applied if the report is already open.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Snedden via AccessMonster.com said:
Thank you so much for your assistance! I did these things that you both
suggest and I now get the report however it is for all records...it
doesn't
just pull the current record that is on screen...what else can I do to fix
this.

Thanks Again for all your help!

Allen said:
Set the button's On Click property to:
[Event Procedure]

Then click the Build button (...) beside the property.
Access opens the code window.
Put the code in between the Private Sub... and End Sub lines.

BTW, the code works better of you concatenate the value into the criteria
string, i.e.:
DoCmd.OpenReport "PrintCustomerReport",acViewPreview, , _
"[OrderID] = " & Forms!frmEditOrder!OrderID

More details in:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html
I am trying to print the information from a current form to a report. I
have
[quoted text clipped - 16 lines]
 
Okay now I am getting this error:

Run-Time Error 2465:
Microsoft Office Access can't find the field 'OrderID' referred to in your
expression.

I did double-check the field name and spelling and I think everything looks
ok but could there be a place that is hidden that I'm not looking...anyway
here is the code that I used which is resulting in this error

If Me.Dirty Then Me.Dirty = False
DoCmd.OpenReport "Print Customer Report", acViewPreview, , "[OrderId]=" & Me!
OrderID

Again, I appreciate all your help with this...it seems to be pretty hard to
get it right but hopefully this is something I can work out.

Thanks Again,

Snedden

Allen said:
Is the form open?

Is the button on this form?

Is there a text box named OrderID on the form?

Does the code compile without error (Compile on Debug menu, in the code
window)?

What error number and exactly what message are you seeing, and which line
gives this error?

As you probably realize, code is really pedantic.
It is now telling me that it can't find the form 'frmEditOrder' but I
double-
[quoted text clipped - 26 lines]
 
Clearly, we cannot see the database, so you will need to debug this for
yourself.

If you don't have a text box for the OrderID field, you could add it to your
form. Set its Visible property to No if you do not wish to see it.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Snedden via AccessMonster.com said:
Okay now I am getting this error:

Run-Time Error 2465:
Microsoft Office Access can't find the field 'OrderID' referred to in your
expression.

I did double-check the field name and spelling and I think everything
looks
ok but could there be a place that is hidden that I'm not looking...anyway
here is the code that I used which is resulting in this error

If Me.Dirty Then Me.Dirty = False
DoCmd.OpenReport "Print Customer Report", acViewPreview, , "[OrderId]=" &
Me!
OrderID

Again, I appreciate all your help with this...it seems to be pretty hard
to
get it right but hopefully this is something I can work out.

Thanks Again,

Snedden

Allen said:
Is the form open?

Is the button on this form?

Is there a text box named OrderID on the form?

Does the code compile without error (Compile on Debug menu, in the code
window)?

What error number and exactly what message are you seeing, and which line
gives this error?

As you probably realize, code is really pedantic.
It is now telling me that it can't find the form 'frmEditOrder' but I
double-
[quoted text clipped - 26 lines]
 
Ok, but I do have a text box for order ID which is visible.

I do thank you for all the help you gave me! As you can see I am a novice
when it come to code.

Snedden

Allen said:
Clearly, we cannot see the database, so you will need to debug this for
yourself.

If you don't have a text box for the OrderID field, you could add it to your
form. Set its Visible property to No if you do not wish to see it.
Okay now I am getting this error:
[quoted text clipped - 39 lines]
 
This time you spelt it with a space in the name.
As I said, the code is really pedantic about things like that.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Snedden via AccessMonster.com said:
Ok, but I do have a text box for order ID which is visible.

I do thank you for all the help you gave me! As you can see I am a novice
when it come to code.

Snedden

Allen said:
Clearly, we cannot see the database, so you will need to debug this for
yourself.

If you don't have a text box for the OrderID field, you could add it to
your
form. Set its Visible property to No if you do not wish to see it.
Okay now I am getting this error:
[quoted text clipped - 39 lines]
 
I got this to work...YEAH!...Thank You Thank You!

I know you don't want to hear from me again...but...can you tell me if it is
possible to print current recor as well as all records that are on a subform
for that particular customer?

Thanks!

Allen said:
This time you spelt it with a space in the name.
As I said, the code is really pedantic about things like that.
Ok, but I do have a text box for order ID which is visible.
[quoted text clipped - 15 lines]
 
Snedden said:
I got this to work...YEAH!...Thank You Thank You!

I know you don't want to hear from me again...but...can you tell me
if it is possible to print current recor as well as all records that
are on a subform for that particular customer?

If you use a query for the report that contains both tables and use grouping for
the details then filtering on the proper customer will automatically result in
also getting the proper child records.

If you use a report with a sub-report then filtering on the proper record in the
parent report will automatically filter on the correct sub-report records.
 
Do you know if I will be able to do this from within a current record which
links to the data in the subform by simply using a control button? I
currently have it set up to click a button the the single record prints to a
report...but I would like to have the current record and the records in the
subform print to the report at a click.

Thanks!
 

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