Form open code not always firing

  • Thread starter Thread starter Ron
  • Start date Start date
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
 
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
 
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)
 
Back
Top