Runtime error 2501 - openform action was canceled

manix

Registered User.
Local time
Today, 00:36
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.
 
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?
 
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!
 
You need to surround your "text" part number with quotes.
stLinkCriteria = "[Part Number]='" & Me![Part Number] & "'"
 
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] & "'"
 
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
 
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:
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.
 
Excellent! You're welcome and glad I could help.
 
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
 
If RecordID is numeric then you do not want the quotes:
MyRecordID = "[RecordID]=" & Me![RecordID]
 
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

Back
Top Bottom