OpenForm action cancelled (Error 2501)

G

Guest

I have one form in a database that has code to open another form from the
record selector. This one works as it should.

I have created a new form and used the same syntax, though with difference
form and match field names, and I am getting this error. I looked in the
newsgroups and found a suggestion about setting macro security to low, but it
was already set to low. I saw another post from a user who thought it was
corruption, deleted the form and imported another from a backup. So I
recreated the form -- no luck. Have also compacted.

Here's the line of code, which I have on the forms OnClick event. I copied
the code from the one that's working and changed the names.

DoCmd.OpenForm "frmDeployRecord", , , "[StateFIPS]=" & Me![StateFIPS]

Any help will be appreciated.
 
F

fredg

I have one form in a database that has code to open another form from the
record selector. This one works as it should.

I have created a new form and used the same syntax, though with difference
form and match field names, and I am getting this error. I looked in the
newsgroups and found a suggestion about setting macro security to low, but it
was already set to low. I saw another post from a user who thought it was
corruption, deleted the form and imported another from a backup. So I
recreated the form -- no luck. Have also compacted.

Here's the line of code, which I have on the forms OnClick event. I copied
the code from the one that's working and changed the names.

DoCmd.OpenForm "frmDeployRecord", , , "[StateFIPS]=" & Me![StateFIPS]

Any help will be appreciated.

I don't see anything wrong in the syntax of your openform code ...
assuming you have a form named "frmDeployRecord" and your record
source table has a field named "StateFIPS" that is a Number datatype.
If it is text datatype, then the syntax should be

DoCmd.OpenForm "frmDeployRecord", , , "[StateFIPS]='" & Me![StateFIPS]
& "'"

Error 2501 is usually caused by the user cancelling the opening of the
form.
Trap that error in the event above used to open the form.

On Error GoTo Err_Handler
DoCmd.OpenForm "frmDeployRecord", , , "[StateFIPS]=" & Me![StateFIPS]

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

Guest

Fred: Thanks so much. The problem was that the underlying field is text, not
numeric, and the code I had copied was for a numeric field. And thanks for
the error handling code.
--
susan


fredg said:
I have one form in a database that has code to open another form from the
record selector. This one works as it should.

I have created a new form and used the same syntax, though with difference
form and match field names, and I am getting this error. I looked in the
newsgroups and found a suggestion about setting macro security to low, but it
was already set to low. I saw another post from a user who thought it was
corruption, deleted the form and imported another from a backup. So I
recreated the form -- no luck. Have also compacted.

Here's the line of code, which I have on the forms OnClick event. I copied
the code from the one that's working and changed the names.

DoCmd.OpenForm "frmDeployRecord", , , "[StateFIPS]=" & Me![StateFIPS]

Any help will be appreciated.

I don't see anything wrong in the syntax of your openform code ...
assuming you have a form named "frmDeployRecord" and your record
source table has a field named "StateFIPS" that is a Number datatype.
If it is text datatype, then the syntax should be

DoCmd.OpenForm "frmDeployRecord", , , "[StateFIPS]='" & Me![StateFIPS]
& "'"

Error 2501 is usually caused by the user cancelling the opening of the
form.
Trap that error in the event above used to open the form.

On Error GoTo Err_Handler
DoCmd.OpenForm "frmDeployRecord", , , "[StateFIPS]=" & Me![StateFIPS]

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

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