Form open code not always firing

R

Ron

My MDB runs a switchboard form on startup. The "on open"
for the switchboard has the code below. Basically, if
the person signing on is a supervisor, it closes the
regular switchboard and opens the supervisor's
switchboard.

The problem is that occasionally, the code doesn't fire
and the sysadmin will wind up with the regular
switchboard. If sysadmin immediately closes and re-opens
the mdb it usually opens correctly.

But how can I get it to consistently open correctly? The
supervisor is going to get honked off if she has to open
it twice to get the correct switchboard.


Private Sub Form_Open(CANCEL As Integer)
If (CurrentUser() = "Sysadmin" Or CurrentUser()
= "rturner") Then
DoCmd.Close
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frm_SupervisorSwitchboard"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
DoCmd.Maximize
End If
End Sub
 
G

Gerald Stanley

I have my doubts about using DoCmd.Close within the Open
eventhandler. Try replacing it with 'Cancel = True' and
see if that improves the situation.

Hope This Helps
Gerald Stanley MCSD
 
V

Van T. Dinh

In addition to what Gerald advised, I would close / cacel
the StartUp Form *after* the opening of the
Form "frm_SupervisorSwitchboard". Something like:

****Untested****
Private Sub Form_Open(CANCEL As Integer)
Dim stDocName As String
Dim stLinkCriteria As String

If (CurrentUser() = "Sysadmin") Or _
(CurrentUser() = "rturner") Then
stDocName = "frm_SupervisorSwitchboard"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoEvents
Cancel = True
Else
DoCmd.Maximize
End If
End Sub
****

HTH
Van T. Dinh
MVP (Access)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top