Form w/ subform Problem

Ciaran

Registered User.
Local time
Today, 00:27
Joined
May 8, 2003
Messages
13
I'm currently trying to fix a bug in a form. On a subform within a form, there is a command button to open up another form. Based on two conditions, it will open up the new form showing the details of that record. (Project ID and Project Date)

It works fine mostly, but sometimes it throws up a run time error, number 2001 "You have cancelled the previous operation". I have 2 copies of the database, one which works fine and another which is currently broken. The problem is that the working version is likely to break on a regular basis.

I have compared the VBA from both versions behind the command button, but still the error exists on the broken version even though the code is exactly the same. Any idea why this is happening?

Code:

Private Sub Command35_Click()
On Error GoTo Err_Command35_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "2e - Project Status Detail Reporting Form"

stLinkCriteria = "[Project ID]=" & Me![Project ID] & "AND me![Project Status Date]=" & "#" & [Project Status Date] & "#"
Refresh

DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command35_Click:
Exit Sub

Err_Command35_Click:

If Err.Number = 2001 Then
MsgBox "Error 2001"

End If
Resume Exit_Command35_Click

End Sub

Any help would be greatly appreciated
 
Help!

Can anyone help me with this problem? Alot of people have been looking at it, but no help yet.

Any help would be greatly appreciated.


Ciaran
 
Ciaran,

Wild guess: Try removing or moving the Refresh statement.

Regards,
Tim
 
Do you have code in the form you are opening that prevents its opening under some condition? The OpenForm is the action it is talking about that has been cancelled.

The syntax is not correct on the OpenForm:

stLinkCriteria = "[Project ID] = " & Me.[Project ID] & "AND [Project Status Date] = " & "#" & Me.[Project Status Date] & "#"

For the future, it is really poor practice to use embedded spaces and special characters in object names.
 
The reason the conventions are bad is because I'm trying to fix a database created by someone before using only wizards.

I tried that code, but the same error occurs.

When you open the form and if you hover over a combo box with project id in it, you get a generic validation error. I usually click ok and then try and open the subform. Is it possible that the error is referring to the validation problem? I'm just cancelling or ignoring it.

Also, do errors in Access persist? ie If I opened the database and produced the validation error, would this fact remain in memory until the next time I opened it?

Thanks

Ciaran
 
Errors do not persist.

You will need to identify the code that is causing the problem. To do this, you'll need to change one of the database options. Open Tools/Options (from the VBA window if you're using A2k or newer). Find the Error Trapping options - they will be on the General tab for A2K or newer. Set the option to - Break on all errors. Now when a trappable error occurs you will get the option to debug. Say yes and examine the code to determine what is causing the problem.
 

Users who are viewing this thread

Back
Top Bottom