Closing a form

MarionD

Registered User.
Local time
Today, 19:24
Joined
Oct 10, 2000
Messages
425
Hi all,

I have to check the "access level" of the current user and close the form if the user is not supposed to have access.

I have put a bit of code on the On Load Event of the form. This works fine, and even displays my message "Access denied"
Now I have tried putting docmd.close or me.undo
but after I ok the message box it opens the form anyway.
How do I stop the form opening at all (or close it straight away)?

This is what I have tried
Select Case pers!SB_UserLevel
Case Is = 3 'mitarbeiter
MsgBox "Access denied",
Me.Undo
DoCmd.close
Case Is = 1, 2 'admin oder Leiter
'nix
Case Else
MsgBox "Access denied",
Me.Undo
DoCmd.close
End Select

Any advice much appreciated!
Thanks
M
 
I would have thought it would be better not to give the user access in the first place?
 
do it in the form's open event:

private sub form_open(cancel as integer)
Select Case pers!SB_UserLevel
Case Is = 3 'mitarbeiter
MsgBox "Access denied",
cancel = True 'do not open this form
Case Is = 1, 2 'admin oder Leiter
'nix
Case Else
MsgBox "Access denied",
cancel=true 'do not open this form
End Select
end sub
 

Users who are viewing this thread

Back
Top Bottom