Runtime error 2501: OpenForm cancelled

PHJ

New member
Local time
Today, 18:28
Joined
Nov 6, 2007
Messages
8
Hi folks
I wonder if anyone can help me (a newbie) with a question. I've got a form and it has a button on it next to a field called Younionize_ID. The idea is that when you click the button it takes you to another form (called Communications), and then to the particular record where the value of ID is the same as the value that was in the Younionize_ID field. The values are both defined as General Number.

To do this I have modified a bit of script which is working fine in a couple of other places (though for text values).

The code that I'm having the problem with is:

Private Sub Younionize_Rep_Click()
DoCmd.OpenForm "Communications", acNormal, , "[ID]='" & Me![Younionize ID] & "'", acFormEdit, acWindowNormal
End Sub

What I get when I click the button is:
Runtime Error 2501
The OpenForm Action was cancelled.

:mad:I've done everything I can to debug, which is admittedly not a hell of a lot. Any ideas????
 
Try this:
....., ,"ID = Forms!FormName!FieldName", acFormEdit......
 
Thanks MStef. I did as you suggested, editing the script to this:

Private Sub Younionize_Rep_Click()
DoCmd.OpenForm "Communications", acNormal, , "ID = Forms!Unions!Younionize ID", acFormEdit, acWindowNormal
End Sub

and got the error message:

"Syntax error (missing operator) in query expression 'ID = Forms!Unions!Younionize ID'.

Frustrating - I feel like I ought to be able to work it out from that, but still can't. Does this error message help??
 
Put
"ID = [Forms]![FormName]![FieldName]"
 
YESSSSS!!!!!

You rock!!!!

And again, and again, cos that's a perfect little snippet of code I'll be able to use all over the place. Thanks very much indeed.
 

Users who are viewing this thread

Back
Top Bottom