Runtime error 2501 - openform action was canceled (1 Viewer)

manix

Registered User.
Local time
Today, 14:14
Joined
Nov 29, 2006
Messages
100
Hi all,

I am really stuck as to why this is happening. I have the following code, whereby a button opens a form on a certain record depending upon the part number field selected on the current form.

The code used for this button is as follows:

Code:
Private Sub showrecord_Click()

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frm_partdata"
    
    stLinkCriteria = "[Part Number]=" & Me![Part Number]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

I keep getting the 2501 error code and it won't open frm_partdata I have checked the forms on open properties and these are clear. Putting a breakpoint in the code I can see it is picking up the right form and the right part number! What am I doing wrong, it works in my other DB's!!!!

Edit: the part number fields are all TEXT fields.
 

boblarson

Smeghead
Local time
Today, 06:14
Joined
Jan 12, 2001
Messages
32,059
Are there any records for that Part Number in that recordset? If there aren't, then it won't open up as there's nothing to open to and therefore it would generate a cancellation error. What happens when you open the form directly without code and search for that part number?
 

manix

Registered User.
Local time
Today, 14:14
Joined
Nov 29, 2006
Messages
100
Are there any records for that Part Number in that recordset? If there aren't, then it won't open up as there's nothing to open to and therefore it would generate a cancellation error. What happens when you open the form directly without code and search for that part number?

Hi Bob,

Yeah the records exist, the form that contains the button actually derives it's records from the same table as the form I am trying to open. It is a summary of non-conforming parts. You can then view details of the parts and edit the data contained for those parts by clicking the button.

I can open the form manually and scrall through all the records with no problem!
 

RuralGuy

AWF VIP
Local time
Today, 07:14
Joined
Jul 2, 2005
Messages
13,826
You need to surround your "text" part number with quotes.
stLinkCriteria = "[Part Number]='" & Me![Part Number] & "'"
 

allan57

Allan
Local time
Today, 14:14
Joined
Nov 29, 2004
Messages
336
Are you sure your field is defined as numeric, if not you need to change your criteria to the following

stLinkCriteria = "[Part Number]='" & Me![Part Number] & "'"
 

manix

Registered User.
Local time
Today, 14:14
Joined
Nov 29, 2006
Messages
100
You need to surround your "text" part number with quotes.
stLinkCriteria = "[Part Number]='" & Me![Part Number] & "'"

Excellent, thanks Ruralguy! I thought it was something to do with that because I have only ever used this function on number fields! I had spent ages trying to figure out where to put the """, but thanks, you have made it work! :D
 

boblarson

Smeghead
Local time
Today, 06:14
Joined
Jan 12, 2001
Messages
32,059
Also, if your form you are trying to open is trying to open the same record that you currently have on your other form, I think your form may not be able to open to the same record as it may be locked by the original form.

Edit: NEVER MIND :)
 
Last edited:

manix

Registered User.
Local time
Today, 14:14
Joined
Nov 29, 2006
Messages
100
Are you sure your field is defined as numeric, if not you need to change your criteria to the following

stLinkCriteria = "[Part Number]='" & Me![Part Number] & "'"

Yeah and again, Allan, thanks.......just what I needed.
 

RuralGuy

AWF VIP
Local time
Today, 07:14
Joined
Jul 2, 2005
Messages
13,826
Excellent! You're welcome and glad I could help.
 

rmtimmah

New member
Local time
Today, 23:14
Joined
Dec 10, 2008
Messages
5
I am having the same issue. Here is the code I have.

Code:
Private Sub Command219_Click()
Dim MyRecordID As String
Dim Myform As String
 
    Myform = "frmWorksheetsPrint"
    MyRecordID = "[RecordID]='" & Me![RecordID] & "'"
    DoCmd.GoToRecord , , acNext
    DoCmd.OpenForm Myform, , , MyRecordID
    DoCmd.Maximize
End Sub

Please help
 

RuralGuy

AWF VIP
Local time
Today, 07:14
Joined
Jul 2, 2005
Messages
13,826
If RecordID is numeric then you do not want the quotes:
MyRecordID = "[RecordID]=" & Me![RecordID]
 

mitrevski

New member
Local time
Today, 15:14
Joined
Sep 20, 2012
Messages
1
Hi all
I have problem with my database. It shows me run time error 2501 open form was cancelled, and when i open debug the error is open in this line: DoCmd.OpenForm "ZaklucenListSpecifikacija", acNormal, , , acFormEdit, acWindowNormal
I have this database on other pc and works perfect.
Can anyone help me to resolve this problem
Thank you in advance
 

Users who are viewing this thread

Top Bottom