Run-time error '2501'

G

Guest

OK, so I've got this Access form that has a print button on it. Essentially
the button is supposed to send the data specific to what's entered in the
form to a report. From there I hit the print button and away we go. Now, I
copied this database to another computer and suddently I get the following
error at random times:

Run-time error '2501':
The RunCommand action was canceled.

Now, here is the code I've used, without any troubles at all on my main
computer:
Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim strCriteria As String

strReportName = "Printable_Returns_Form_rpt"
strCriteria = "[Return Number]=" & Me![Return Number]

DoCmd.RunCommand acCmdSave
Me.Requery

DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

End Sub

The line "DoCmd.RunCommand acCmdSave" is where the debugger takes me when I
get this error. I've tried searching on MS' Knowledgebase only to find some
info relating to Access 97. I'm using Access 2003. Again, this has worked
just fine from my computer. When I moved it to another, it gives this error.
Though it doesn't do it all the time.

Any ideas? Is my code just outdated code that I need to change? I'd gotten
the suggestion for this code from one of those Access help forums out there
but it's been a few years. I think at that point I developed the database on
either Access XP or else Access 2000. Thanks for any help you guys can offer!
 
F

fredg

OK, so I've got this Access form that has a print button on it. Essentially
the button is supposed to send the data specific to what's entered in the
form to a report. From there I hit the print button and away we go. Now, I
copied this database to another computer and suddently I get the following
error at random times:

Run-time error '2501':
The RunCommand action was canceled.

Now, here is the code I've used, without any troubles at all on my main
computer:
Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim strCriteria As String

strReportName = "Printable_Returns_Form_rpt"
strCriteria = "[Return Number]=" & Me![Return Number]

DoCmd.RunCommand acCmdSave
Me.Requery

DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

End Sub

The line "DoCmd.RunCommand acCmdSave" is where the debugger takes me when I
get this error. I've tried searching on MS' Knowledgebase only to find some
info relating to Access 97. I'm using Access 2003. Again, this has worked
just fine from my computer. When I moved it to another, it gives this error.
Though it doesn't do it all the time.

Any ideas? Is my code just outdated code that I need to change? I'd gotten
the suggestion for this code from one of those Access help forums out there
but it's been a few years. I think at that point I developed the database on
either Access XP or else Access 2000. Thanks for any help you guys can offer!

Regarding > DoCmd.RunCommand acCmdSave <
What are you trying to Save? The Form?
Or the Data just entered into the form?
Most likely the data, in which case you need acCmdSaveRecord.

Private Sub cmdPrintRecord_Click()
On Error GoTo Err_Handler
DoCmd.RunCommand acCmdSaveRecord
Dim strReportName As String
Dim strCriteria As String
strReportName = "Printable_Returns_Form_rpt"
strCriteria = "[Return Number]=" & Me![Return Number]
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 then
Else
MsgBox "Error# " & Err.Number & " " & Err.Description
End If
Resume Exit_This_Sub
End Sub
 
G

Guest

fredg said:
OK, so I've got this Access form that has a print button on it. Essentially
the button is supposed to send the data specific to what's entered in the
form to a report. From there I hit the print button and away we go. Now, I
copied this database to another computer and suddently I get the following
error at random times:

Run-time error '2501':
The RunCommand action was canceled.

Now, here is the code I've used, without any troubles at all on my main
computer:
Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim strCriteria As String

strReportName = "Printable_Returns_Form_rpt"
strCriteria = "[Return Number]=" & Me![Return Number]

DoCmd.RunCommand acCmdSave
Me.Requery

DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

End Sub

The line "DoCmd.RunCommand acCmdSave" is where the debugger takes me when I
get this error. I've tried searching on MS' Knowledgebase only to find some
info relating to Access 97. I'm using Access 2003. Again, this has worked
just fine from my computer. When I moved it to another, it gives this error.
Though it doesn't do it all the time.

Any ideas? Is my code just outdated code that I need to change? I'd gotten
the suggestion for this code from one of those Access help forums out there
but it's been a few years. I think at that point I developed the database on
either Access XP or else Access 2000. Thanks for any help you guys can offer!

Regarding > DoCmd.RunCommand acCmdSave <
What are you trying to Save? The Form?
Or the Data just entered into the form?
Most likely the data, in which case you need acCmdSaveRecord.

Private Sub cmdPrintRecord_Click()
On Error GoTo Err_Handler
DoCmd.RunCommand acCmdSaveRecord
Dim strReportName As String
Dim strCriteria As String
strReportName = "Printable_Returns_Form_rpt"
strCriteria = "[Return Number]=" & Me![Return Number]
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 then
Else
MsgBox "Error# " & Err.Number & " " & Err.Description
End If
Resume Exit_This_Sub
End Sub

Thanks for the help! Now my question is, what code would I use to clear the
data in that form? All the info entered into the form each time is stored in
a couple different tables but obviously after filling the form out and
printing I want to have the data clear out so that new info can be entered.

As for your question about using the DoCmd.RunCommand acCmdSave in my
original code, honestly, I had this issue with trying to get Access to send
data from a form to a report where I could then print it out and that's the
code someone suggested to me. I'm by no means an expert on Visual Basic. I
understand the basic syntax of how some of it works thanks to having learned
other languages in the past but until recently I'd never bothered to try and
learn VB. But now I am starting to learn VB simply because it does appear to
be one of the more widely used languages for anything from program
development to web development.

Thanks again for your help Fred! Really appreciate it!
 

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