Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I changed my primary key data type 1

Status
Not open for further replies.

PADFOR

Programmer
Feb 5, 2001
25
GB
I changed my primary key data type from integer to text, but when I go to open form using the primary key selected from the combo box, I receive the following message:

Microsoft Access

Run-time error '2501':

The OpenForm action was canceled.

You used a method of the DoCmd object to carry out an action in Visual Basic, but then clicked Cancel in a dialog box.

For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that asks if you want to save the changes you made to the form.

I have included the code below:

Private Sub cmdNext_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim var As Variant

var = Forms![frmMaintainableItemParentSelection]![cmboMaintainableItemParentTag]

If IsNull(var) Then

MsgBox "No Maintainable Item Parent Tag has been selected, please select a maintainable Item Parent Tag", , "Maintainable Item Parent Tag Warning"

Else

stDocName = "frmEditMaintainableItemParentData"
stLinkCriteria = "[MaintainableItemParentTag]=" &
Me![cmboMaintainableItemParentTag]
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit

End If

End Sub

The program stops at this line:

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit

Any help would be appreciated.

Regards

PADFOR
 
A suggestion: Open your form in design mode and look at its RecordSource property. This could be a table name, a query name, a SQL statement, or blank.

If it's a table or query name, open the table or query from the database window. You might get an error message; if so, this error is happening in the OpenForm logic, and if it's not expected it could cause the open to be canceled.

If it's a SQL statement, create a new query from the database window, switch to SQL view, and copy the statement into it. Then switch to datasheet view. Again, you might get an error message; handle it as above.

If the RecordSource is blank, or if the above procedures don't result in an error message, the problem is in the form's Form_Open event procedure. First choose Tools>Options>Advanced from the menu, and in the Error Handling section choose Break On All Errors. Then open the form in Form View and you should get an error breakpoint showing where the error occurs.

You can also set a breakpoint on the first statement of this procedure, then open the form in Form View and single step until you either get an error message or jump to an error handler within the procedure. At the breakpoint within the event procedure, you can use the Debug Window (called the Immediate Window in Access 2000) to investigate the error number, and the values of any variables and arguments used in the failing statement. Rick Sprague
 
I have tried your suggestions, but it still reports the same error. Any more suggestions?

PADFOR
 
Hi PADFOR,

One possible problem (don't know if it's the problem, but it's a problem..):

Try the following. Change the following line of code:
stLinkCriteria = "[MaintainableItemParentTag]=" &
Me![cmboMaintainableItemParentTag]


To:

stLinkCriteria = "[MaintainableItemParentTag] = '" &
Me![cmboMaintainableItemParentTag] & "'"


Note the single quotation marks around the criteria in the expression. These are needed for text criteria to work.

Hope that helps! :)
 
Thank you for your solution, It works.

PADFOR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top