Using If to load correct form on DB open (1 Viewer)

WineSnob

Not Bright but TENACIOUS
Local time
Yesterday, 22:07
Joined
Aug 9, 2010
Messages
211
I am trying to load a form based on an if statement. I think my issue is that I have the DB set to Display form "frmSplash" on open. I have tried the following (frmSplash form load event) but it continues past the frmMenu and stops at the frmSplash. I want to open the DB and look to see if it is registered and if yes then open frmMenu. There is 1 record in tblRegistration so it should open to frmMenu. I checked and it is seeing the 1 record.
Code:
Private Sub Form_Load()

Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("SELECT * FROM [tblRegistration]")
     If rs.RecordCount > 0 Then
    
DoCmd.OpenForm "frmMenu", acNormal, , , , acWindowNormal
     Else
 
    DoCmd.OpenForm "frmSplash"
    End If
  
 End Sub
Does the display form on open override all?
Any suggestions on how to achieve to goal?
 

Frothingslosh

Premier Pale Stale Ale
Local time
Yesterday, 22:07
Joined
Oct 17, 2012
Messages
3,276
My recommendation would be to use an actual startup procedure rather than trying to code this into frmSplash.

Basically, write up a function that checks to see which form to open, then opens either frmMenu or frmSplash as appropriate. Name it whatever you want, although I always call my startup routines 'Startup' for some reason. :D This function needs to be in a global module, not a form.

In frmSplash, I'd just put a function in the 'On Load' event that runs a timer for a couple seconds, then closes the splash and opens the menu. Or you can make the splash a pop-up, and when they hit the close button, frmMenu opens.

Now create a macro called 'AutoExec'. For the action, have it run code, and for the procedure name, enter your startup function. Please note that this macro action (at least in 2007 and earlier) can only run functions, not subroutines.

Finally, clear out 'load on startup'. Your function will handle it now rather than Access.
 

Users who are viewing this thread

Top Bottom