VBA - error 2501 with opening next form

WalterInOz

Registered User.
Local time
Tomorrow, 02:57
Joined
Apr 11, 2006
Messages
93
I'm trying to close a form (frmIN) that shows details of selected correspondence about a project and go back to the main form (frmMain) of that particular project.

I'm using the code below that doesn't work properly. I get error message '2501 - OpenForm action was cancelled'

Anyone any suggestions as to what is wrong with the code and why?
Thanks for your help,
Walter

Private Sub btnClose_Click()
Dim StrMsg As String
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmIN"
DoCmd.Save

stDocName = "frmMain"
stLinkCriteria = "[projectID]=" & "'" & Me![ProjectID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


stDocName = "frmIN"
DoCmd.close

End Sub
 
I would suggest a couple of things:

1. Try running opening the form without the stLinkCriteria option.
2. The DoCmd.Save only saves the structure of the form and not the data. Try 'DoCmd.RunCommand, acCmdSaveRecord' instead

There may be an issue with the syntax of your stLinkCriteria. (I don't find the syntax of passing variables etc to SQL at all intuitive!!).

HTH
 
Last edited:
Changed the save method to the proper one and have puttered around a bit some more with the rest of the code. No luck though. I'm spending way to much time on this so I've left it for later and made that button invisible for the moment. Will try again later to optimise the DB.
 

Users who are viewing this thread

Back
Top Bottom