M
Michel S.
posted this yesterday in the general forum but since I haven't foud a
solution, I submit my problem here, where it belongs. Sorry.
I'm using Access 2002.
I have a form with the following code in its Open event :
Private Sub Form_Open(Cancel As Integer)
If IsOkToProceed = False Then
MsgBox "Can't use this form now - Open canceled"
Cancel = True
End If
End Sub
The IsOkToProceed return false (I added the MsgBox to verify it) and
cancel is set to true.
If I Open the form directly from the database window, it correctly
displays the message and return to the datatbase window.
But if I open the form with the following code located behing another
form, I noted that even if Cancel is set to true in the Open event, the
form's code execution continues with the "Load" event, etc.. until it
fails at the end of the "Current" event. (I set MsgBox in these events
as well to make sure they were executed in that case but not when
opened from the database window)
Private Sub cmdImport_Click()
On Error Resume Next
DoCmd.OpenForm Form_ImportData, acNormal, , , acFormReadOnly, _
acWindowNormal
MsgBox Err.Number ' <-- displays 2001
End Sub
BTW, if I remove the "On Error" statement, the message dispalyed is
"Error 2001 - Error set by application or object"; isn't it supposed to
be "Error 2001 - You canceled the previous operation" ?).
The problem is that the load and current events perform operations I
don't want to do if the form can't be used. I always can avoid this by
setting a module flag, but why work around things that aren't supposed
to occur on the first place ?
I tried to decompile and import the forms and modules in another
database container, but at no avail.
Any idea ?
Thanks
solution, I submit my problem here, where it belongs. Sorry.
I'm using Access 2002.
I have a form with the following code in its Open event :
Private Sub Form_Open(Cancel As Integer)
If IsOkToProceed = False Then
MsgBox "Can't use this form now - Open canceled"
Cancel = True
End If
End Sub
The IsOkToProceed return false (I added the MsgBox to verify it) and
cancel is set to true.
If I Open the form directly from the database window, it correctly
displays the message and return to the datatbase window.
But if I open the form with the following code located behing another
form, I noted that even if Cancel is set to true in the Open event, the
form's code execution continues with the "Load" event, etc.. until it
fails at the end of the "Current" event. (I set MsgBox in these events
as well to make sure they were executed in that case but not when
opened from the database window)
Private Sub cmdImport_Click()
On Error Resume Next
DoCmd.OpenForm Form_ImportData, acNormal, , , acFormReadOnly, _
acWindowNormal
MsgBox Err.Number ' <-- displays 2001
End Sub
BTW, if I remove the "On Error" statement, the message dispalyed is
"Error 2001 - Error set by application or object"; isn't it supposed to
be "Error 2001 - You canceled the previous operation" ?).
The problem is that the load and current events perform operations I
don't want to do if the form can't be used. I always can avoid this by
setting a module flag, but why work around things that aren't supposed
to occur on the first place ?
I tried to decompile and import the forms and modules in another
database container, but at no avail.
Any idea ?
Thanks