Error message 2136

  • Thread starter Thread starter James
  • Start date Start date
J

James

I have a form that opens the "Find" form from Access. However if there are
no records is give a run-time error sometime and other just an error mesage
with an ok button. I tried to use the If...Then...End but it still gave the
error. The code is below. Any help on this is greatly appreciated.

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Err.Description
Resume Exit_Form_Open

End Sub
 
Hello.

Add this code to the beginning of the event procedure:


If NewRecord Then Exit Sub

..

If the form does not allow additions, then NewRecord will
not be set. In that case, you need to add some code to the
error handler:

Err_Form_Open:
If Err.Number = 2136 Then Exit Sub

..


Regards,
Ivar Svendsen
 
Thank you for your help. I tried the code that you gave
and it still gave me the same error. The code that I have
is below.

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

If NewRecord Then Exit Sub
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, ,
acMenuVer70

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Err.Description
Resume Exit_Form_Open

End Sub
 
Hello.

Did you try this rewrite:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

If NewRecord Then Exit Sub
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, ,
acMenuVer70

Exit_Form_Open:
Exit Sub

Err_Form_Open:

' >> Start of new code
if err.number = 2136 then exit sub
' << End of new code
MsgBox Err.Description
Resume Exit_Form_Open

End Sub


If this does not work, you need to put a breakpoint at the
line with the new "if" statement. Then switch to the
immediate window, and type the command

Print Err.Number

This will give you the correct number to compare with
in "Err.Number="



..
 
This is what I tried. It still gives the same error message. I used the
Print Err.Number thing and it returned 2137 so I changed the number.

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_Form_Open:
Exit Sub

Err_Form_Open:

If Err.Number = 2137 Then Exit Sub
MsgBox Err.Description
Resume Exit_Form_Open
End Sub
 
Back
Top