Print Form with command button?

D

DTW

Guys,
I know this has been discussed to death, but I still can't get it done.

I have a Master form with a subform. I have set a command button on the form
with the following code to hopefully print just one form the current form. I
cannot get it to work.

The name of the Master form = "Bill Back With Customers"
name of subform = "Bill Back" (Primary Key = "BillBackNumber " which is
autonumber)
name of report = "Bill Back Form Report"

I copied the form and constructed a report named Bill back Form Report. I
have a query set up to run the report. I have no filters in the report.

Here is the code behind the Subform "Bill Back" print button

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 = "[BillBackNumber] =" & Me.[BillBackNumber]
DoCmd.OpenReport "Bill Back Form Report", acViewPreview, , strWhere
End If
End Sub


I copied it from one of the threads on the forum and tried to set it to my
report and forms.

I am struggling with this.. now several nights.. I need to get it up and
running for work.

One question that is rolling around in my dumb mind is how to filter a query
in a report to have the report print the newest or highest autonumber (in my
case BillBackNumber)?

Thanks for any help...

DTW
 
G

Guest

Can you be more specific about what errors you are getting, what results you
are getting or not getting?
If you are getting an error, please specify the error number and identifiy
the line that is causing the error.
 
D

DTW via AccessMonster.com

Klatuu said:
Can you be more specific about what errors you are getting, what results you
are getting or not getting?
If you are getting an error, please specify the error number and identifiy
the line that is causing the error.

Thank you for responding.. I need help.. Thank you for your time.

When my sub form " Bill Back" is blank (new record) I get the following:

When I click the command button I get this error:

Run Time error '3021' No currecnt record.

Debug highlights this code:

DoCmd.OpenReport "Bill Back Form Report", acViewNormal, , strWhere

If I bring a current record that contains data into my "Bill Back" form, when
I click the print command I get the following error:

Run Time Error: 3075
Extra ) in query expression '([BillBackNumber]=)'.

Thanks for your help again.
 
G

Guest

The 3075 error I don't get. The code apprears to be correct.
The 3021 is normal. You will need to handle that in the NoData event of
your report; however, it will still throw the error in the form, so you need
to add an error handler routine to you sub and handle that error however you
want.

DTW via AccessMonster.com said:
Klatuu said:
Can you be more specific about what errors you are getting, what results you
are getting or not getting?
If you are getting an error, please specify the error number and identifiy
the line that is causing the error.

Thank you for responding.. I need help.. Thank you for your time.

When my sub form " Bill Back" is blank (new record) I get the following:

When I click the command button I get this error:

Run Time error '3021' No currecnt record.

Debug highlights this code:

DoCmd.OpenReport "Bill Back Form Report", acViewNormal, , strWhere

If I bring a current record that contains data into my "Bill Back" form, when
I click the print command I get the following error:

Run Time Error: 3075
Extra ) in query expression '([BillBackNumber]=)'.

Thanks for your help again.
 
D

DTW via AccessMonster.com

Thanks again. If you would please give me an example of the code to place in
the NoData event, I would appreciate it.

Thanks
The 3075 error I don't get. The code apprears to be correct.
The 3021 is normal. You will need to handle that in the NoData event of
your report; however, it will still throw the error in the form, so you need
to add an error handler routine to you sub and handle that error however you
want.
[quoted text clipped - 20 lines]
Thanks for your help again.
 
G

Guest

This would go in your report's module:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No Data Matching Selections", vbInformation + vbOKOnly, "BPO By
HomeRoom"
Cancel = True
End Sub


DTW via AccessMonster.com said:
Thanks again. If you would please give me an example of the code to place in
the NoData event, I would appreciate it.

Thanks
The 3075 error I don't get. The code apprears to be correct.
The 3021 is normal. You will need to handle that in the NoData event of
your report; however, it will still throw the error in the form, so you need
to add an error handler routine to you sub and handle that error however you
want.
Can you be more specific about what errors you are getting, what results you
are getting or not getting?
[quoted text clipped - 20 lines]
Thanks for your help again.
 

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