Autoexec & Form loading

sumdumgai

Registered User.
Local time
Today, 14:09
Joined
Jul 19, 2007
Messages
453
I've tried several approaches but cannot get this to work. I have an FE that has an Autoexec macro. In the macro, I check user name against a table. If the user name is invalid, I want to display a message and quit the application. However, when Access opens, it defaults to a Form.



How can I quit the application before the form gets loaded? Or how to I close the form and then quit?



Thanks.
 
Hi. Have you considered not setting up the form to open up automatically? You can just open it using your Autoexec macro. Just a thought...
 
I would have thought your form would be a login form.?

I did it like this
Code:
Option Compare Database
Option Explicit
Public ilogins As Integer

Private Sub cmdLogin_Click()
Dim strFormName As String

strFormName = Me.Name
' Check the password
If Nz(Me.txtUserPassword, "InvalidPassword") <> Me.cboEmployeeID.Column(2) Then
    MsgBox "Invalid Password "
    ilogins = ilogins + 1
    Me.txtUserPassword = ""
    Me.txtUserPassword.SetFocus
    If ilogins > 2 Then
        DoCmd.Quit
    End If
    
Else
    TempVars("EmployeeID").Value = Me.cboEmployeeID.Column(0)
    TempVars("Employee").Value = Me.cboEmployeeID.Column(1)
    TempVars("UserLevel").Value = DLookup("DataOrder", "tblLookup", "LookupID = " & Me.cboEmployeeID.Column(3))
    DoCmd.OpenForm "Switchboard"
    DoCmd.Close acForm, strFormName
End If
End Sub

HTH
 
As theDBGuy said you simply need to go to File/Options/Current Database and select None for the opening form. Then in your AutoExec macro you add a line to open the form you want if the user name is valid.

Cheers,
Vlad
 
Even if it's not a login form, if you set the Default form, put code in the form Open event instead of AutoExec macro. The point is, one or the other, don't mix.
 
If you have a Form_Open event, you can cancel the opening of a form by setting the Cancel parameter to TRUE. Otherwise, your form WILL open and it will be HELL to close until you reach the Form_Current event. So if you are doing something to launch an app, you need a way to tell the app "don't open the form." That usually means (as you are correct to state) determining whether you like the current user.

If your app is locked down enough (search this forum for "Securing a Database" as a topic), then closing the default opening form in the _Open routine will block opening the app. But if you wish, as the last thing you execute on the path to saying "bye-bye" you can attempt to execute an Application.Quit to force Access to exit from that _Open code. Since you were also returning Cancel=TRUE, that combination is pretty much final.

Note that in this context, you cannot expect to display anything other than perhaps a pop-up message-box type of object because in the _Open event, you have opened the object that is the form and you have started to open its .Recordsource, but you have not yet loaded any of the controls or visual details. (See also Form_Load...)
 

Users who are viewing this thread

Back
Top Bottom