Opening report

  • Thread starter injanib via AccessMonster.com
  • Start date
I

injanib via AccessMonster.com

Hi

I have a form with a field name "txtInvoice". The record source of the field
is a field called "Invoice Number" in a table. The form has a subform too. I
have a button that is supposed to print which ever invoice I have pulled up,
so I have it coded as follows.

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then
Me.Dirty = True
End If


strWhere = "[Invoice Number] = """ & Me.[txtInvoice] & """"
DoCmd.OpenReport "InvoiceReport", acViewPreview, , strWhere

End Sub

Everytime I click on the button I get a "Run-time error '2501', The
openreport action was canceled".
can someone tell me what the problem is.
 
J

John W. Vinson

Hi

I have a form with a field name "txtInvoice". The record source of the field
is a field called "Invoice Number" in a table. The form has a subform too. I
have a button that is supposed to print which ever invoice I have pulled up,
so I have it coded as follows.

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then
Me.Dirty = True
End If


strWhere = "[Invoice Number] = """ & Me.[txtInvoice] & """"
DoCmd.OpenReport "InvoiceReport", acViewPreview, , strWhere

End Sub

Everytime I click on the button I get a "Run-time error '2501', The
openreport action was canceled".
can someone tell me what the problem is.

What's the datatype of Invoice Number? The code above should work if it is a
Text field; ifi it's a number lose the extra quotes:

strWhere = "[Invoice Number] =" & Me.[txtInvoice]
 
M

Marshall Barton

injanib said:
I have a form with a field name "txtInvoice". The record source of the field
is a field called "Invoice Number" in a table. The form has a subform too. I
have a button that is supposed to print which ever invoice I have pulled up,
so I have it coded as follows.

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then
Me.Dirty = True
End If


strWhere = "[Invoice Number] = """ & Me.[txtInvoice] & """"
DoCmd.OpenReport "InvoiceReport", acViewPreview, , strWhere

End Sub

Everytime I click on the button I get a "Run-time error '2501', The
openreport action was canceled".


That error means pretty much what it says. Does the report
use Cancel - True in it's Open event or use the Nodata event
when the report has no records to display?
 
I

injanib via AccessMonster.com

The is no event procedure set up on the report itself. Plus, This happens
when there is record to be displayed.

The Invoice field is a text field.


Marshall said:
I have a form with a field name "txtInvoice". The record source of the field
is a field called "Invoice Number" in a table. The form has a subform too. I
[quoted text clipped - 16 lines]
Everytime I click on the button I get a "Run-time error '2501', The
openreport action was canceled".

That error means pretty much what it says. Does the report
use Cancel - True in it's Open event or use the Nodata event
when the report has no records to display?
 
M

Marshall Barton

Sorry, I see no other clues to why you would get that
message.

Double check that the invoice no. does not contain an
apostrophe.

Regardless of that problem, you should change the code to
use:
Me.Dirty = FALSE
-
Marsh
MVP [MS Access]

The is no event procedure set up on the report itself. Plus, This happens
when there is record to be displayed.

The Invoice field is a text field.


Marshall said:
I have a form with a field name "txtInvoice". The record source of the field
is a field called "Invoice Number" in a table. The form has a subform too. I
[quoted text clipped - 16 lines]
Everytime I click on the button I get a "Run-time error '2501', The
openreport action was canceled".

That error means pretty much what it says. Does the report
use Cancel - True in it's Open event or use the Nodata event
when the report has no records to display?
 

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

Similar Threads

Outputting to PDF in A2007 0
If, Then Button Code 1
Printing Report 3
Print the record in the form 1
Report VB Code 1
Print Filter Not Working 0
Subform Search Function 2
Command button to open report 1

Top