Modal login form not pausing code???

  • Thread starter Corey-g via AccessMonster.com
  • Start date
C

Corey-g via AccessMonster.com

Hi All,

I have read throughout the forums that opening a form as "acDialog" will
cause your code to stop and wait for the form to finish or whatever. It
doesn't seem to be working that way for me...

Here's what I'm doing:

Open app to a splash screen
Splash screens 'form_open' event checks to see if logged in. If not opens
the login form

If Not valid Then
DoCmd.OpenForm "frmLogin", , , , , acDialog
End If

The login form has only 2 functions (btnLogin_Click & btnClose_Click)

I thought my code would pause until the form was either closed or the login
button clicked, but that doesn't happen...

Login Form's "Form" settings (other tab) Pop Up = YES, Modal = YES

Am I missing something?

TIA,

Corey
 
R

Rick Brandt

Corey-g via AccessMonster.com said:
Hi All,

I have read throughout the forums that opening a form as "acDialog" will
cause your code to stop and wait for the form to finish or whatever. It
doesn't seem to be working that way for me...

Here's what I'm doing:

Open app to a splash screen
Splash screens 'form_open' event checks to see if logged in. If not opens
the login form

If Not valid Then
DoCmd.OpenForm "frmLogin", , , , , acDialog
End If

The login form has only 2 functions (btnLogin_Click & btnClose_Click)

I thought my code would pause until the form was either closed or the login
button clicked, but that doesn't happen...

Login Form's "Form" settings (other tab) Pop Up = YES, Modal = YES

Am I missing something?

Are you saying you have additional lines of code after...

DoCmd.OpenForm "frmLogin", , , , , acDialog

....and they are running before you close frmLogin? Because that shouldn't
happen.

You don't need Popup and Modal set in the form's design view as acDialog takes
care of that for you (but having them set should be harmless).

Your syntax is correct so I'm stumped. The only thing I have seen similar to
this is when people tried to use it on a datasheet form (datasheets cannot be
opened modally so acDialog is ignored).

Post your full code.
 
C

Corey-g via AccessMonster.com

I'm pretty stumped too... Here is the code for each piece:

Splash Screen On Load proc:

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

Me.lblSplashScreenBanner.Caption = "Authenticating..."
Me.Visible = True
' Test Authentication
If Not valid Then
DoCmd.OpenForm "frmLogin", , , , , acDialog
End If
Debug.Print "After Open Login IF Statement"
Me.lblSplashScreenBanner.Caption = "Authenticated..."

FunctionExit:
Exit Sub
ErrorHandler:
Dim tThisError As typErrStr
Dim result As Boolean

With tThisError
.lngErrNum = Err.Number
.strErrDesc = Err.Description
.strErrSource = "Module: frmSplashScreen, Form_Open()"
.strErrDetail = "Not sure what to have here..."
.bErrReviewed = True
.bErrNotificationSent = False
End With
result = LogError(tThisError)
If result Then
Resume FunctionExit
End If
End Sub

The "frmLogin" doesn't have an "On Load" or "Form_Open" event, only
"btnLogin_Click" and "btnClose_Click"

When I set the breakpoint on the "If valid then" statement and test the form,
then F8 to step through, the login form opens, but hitting F8 then keeps the
code going (back to the frmSplash_Screen code, and prints the debug statement
to the imediate window). If I hit F5, the login form is visible, but again
the imediate window shows the "After Open Login IF Statement" and the splash
screen shows the "Authenticated...", even though I haven't done anything with
the Login form. The login form is set to be in form view only.

Code for the frmLogin:
********************************************************************************
Option Compare Database
Option Explicit

Private Sub btnClose_Click()
valid = False
DoCmd.Close acForm, "frmLogin"
End Sub

Private Sub btnLogin_Click()
On Error GoTo ErrorHandler
'Test to make sure that there is something entered
If Me.txtUsername.Value = "" Then
MsgBox "You must provide a Username to continue", vbCritical, "Login
Alert"
GoTo FunctionExit
End If
If Me.txtPWD.Value = "" Then
MsgBox "You must provide a Password to continue", vbCritical, "Login
Alert"
GoTo FunctionExit
End If
' Check UID & PWD
valid = ValidateCreds(Me.txtUsername.Value, Me.txtPWD.Value)

If valid = False Then
MsgBox "The Username or Password entered is invalid." & _
vbCrLf & "Please re-enter your Username and Password" & _
vbCrLf & "Attempts left:" & intAttempts, vbExclamation, "Login Alert"
End If

Me.Visible = False
Debug.Print "Should have checked Authentication"

FunctionExit:

Exit Sub

ErrorHandler:
Dim tThisError As typErrStr
Dim result As Boolean
With tThisError
.lngErrNum = Err.Number
.strErrDesc = Err.Description
.strErrSource = Err.Source
.strErrDetail = strSQL
.bErrReviewed = True
.bErrNotificationSent = False
End With
result = LogError(tThisError)
If result Then
Resume FunctionExit
End If

End Sub

What am I missing?

Corey
 
R

Rick Brandt

Corey-g via AccessMonster.com said:
I'm pretty stumped too... Here is the code for each piece:

Stepping throught the code might be confusing things. Just put a MsgBox()
immediately after the line that opens the dialog form and see if the message
is displayed before or after you close the form. If it waits until you
close (or hide) the dialog form then it is working as expected.
 
C

Corey-g via AccessMonster.com

Well, I see the MSGBOX almost as fast as the login form...

So, even though I have tried to open the form using acDialog, Access doesn't
seem to wait until the form has closed before continuing...

Any other thoughts?

TIA,

Corey
 
R

Rick Brandt

Corey-g via AccessMonster.com said:
Well, I see the MSGBOX almost as fast as the login form...

So, even though I have tried to open the form using acDialog, Access
doesn't seem to wait until the form has closed before continuing...

Any other thoughts?

As a test create a new form and open that with acDialog instead of your
existing one. Have NO code or RecordSource on the test form and see if the
behavior is any different.
 
A

Albert D.Kallal

At a note, opening the on open, or on-load event means that the current form
will NOT load UNLESS that dialog form is closed....

So, it is not clear how the first form is handling this problem, but it will
NOT be loaded if the dialog form is opened in the on-open/on-load event...

This also means that the logon form can't reference anything in the
splash/load form
 

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