AutoExec as vba instead? (1 Viewer)

mistyinca1970

Member
Local time
Yesterday, 19:17
Joined
Mar 17, 2021
Messages
117
I was thinking an order like this:

  1. set an unbound form as the database's Startup form (Access Options > Current Database > Display Form)
  2. there, do anything you need to do to ensure/provide the user with a connection to any later bound forms. test their connection, create a connection, etc
  3. finally, depending on the outcome of #2, load any forms that involve bound data or connections
If your users are presented with that enable content, and don't click it, all bets are off anyway - nothing automated is going to happen.

There are many threads that deal with the problem of trying to make your database more fool proof when it comes to Trusted Locations.
Search results for query: database trusted location | Access World Forums (access-programmers.co.uk)
Sorry I have been on vacation, but now back to business :cry:...
I'm still having trouble with this one. I don't know how to create an "if" scenario that recognizes when content is not enabled. If you could set me in the right direction, that would be great.
Thanks!
 

Isaac

Lifelong Learner
Local time
Yesterday, 19:17
Joined
Mar 14, 2017
Messages
8,774
Hope your vacation was nice.

I previously mentioned:
If your users are presented with that enable content, and don't click it, all bets are off anyway - nothing automated is going to happen.

What I meant by that is, you can't write code to determine that code can't be run.
Well, you can write it, it just won't run or work.

That would be like a computer knowing it was turned off, or a person knowing they were dead, unless in the context of an awful Bruce Willis movie.

So you can instead try to solve for the problem of Trusted Locations in the first place - so that later, your content will be 'Enabled':
There are many threads that deal with the problem of trying to make your database more fool proof when it comes to Trusted Locations.
Search results for query: database trusted location | Access World Forums (access-programmers.co.uk)
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:17
Joined
Oct 29, 2018
Messages
21,453
Hi Misty. Pardon me for jumping back in. To handle the problem with enabling content, you can either go the ACCDR/Runtime route as @Isaac mentioned earlier, or go back to using an Autoexec macro. Safe macro actions can execute even if the content is not yet enabled. That's what I do sometimes. I either show a message box or a form (using an image) to remind the user to enable content.
 

mistyinca1970

Member
Local time
Yesterday, 19:17
Joined
Mar 17, 2021
Messages
117
Hi Misty. Pardon me for jumping back in. To handle the problem with enabling content, you can either go the ACCDR/Runtime route as @Isaac mentioned earlier, or go back to using an Autoexec macro. Safe macro actions can execute even if the content is not yet enabled. That's what I do sometimes. I either show a message box or a form (using an image) to remind the user to enable content.
Please jump in! (y)This is the route I would prefer to go. I have tried the following alternate sequence (this one does not use an autoexec), but even the form's on load event isn't working without content enabled. The most important being hiding the toolbar. But when I open it when content isn't enabled, the ribbon is showing.
  1. Current Database Application Options set frmOpen (unbound) as the Display form
    1. the on load event of this form is:
      Code:
       Private Sub Form_Load()
      On Error GoTo Form_Load_Err
      
      DoCmd.ShowToolbar "ribbon", acToolbarNo
      
      Cleanup:
      Exit Sub
      Form_Load_Err:
      Select Case Err.Number
      Case 3044
      Beep
      MsgBox "You must be connected to the Network or the County VPN to open Contrax™! Once you are connected, try opening Contrax™ again.", vbCritical, "Not Connected to Network"
      Application.Quit acQuitSaveNone
      Case 2950
      Beep
      MsgBox "You will need to enable content prior to logging in to Contrax™ for the first time from this file location. Close the login box, then click the 'Enable Content' box at the top of the screen. After this, you should not have to do this again when opening Contrax™ from this location", vbCritical, "Enable Content Upon First Login"
      DoCmd.Close frmLogin
      Case Else
      Beep
      MsgBox "There is a problem opening Contrax™. Contact the administrator for help.", vbCritical, "Contrax™ Not Available"
      Application.Quit acQuitSaveNone
      End Select
      
      Resume Cleanup
      
      End Sub
    2. Once enabled, the user can click the login button to load the login form, which then activates the sequence of opening the forms for use.
So what kind of macros are considered safe before content is enabled? I really need that toolbar to hide.
login.PNG

Thanks!
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:17
Joined
Oct 29, 2018
Messages
21,453
Please jump in! (y)This is the route I would prefer to go. I have tried the following alternate sequence (this one does not use an autoexec), but even the form's on load event isn't working without content enabled. The most important being hiding the toolbar. But when I open it when content isn't enabled, the ribbon is showing.
  1. Current Database Application Options set frmOpen (unbound) as the Display form
    1. the on load event of this form is:
      Code:
       Private Sub Form_Load()
      On Error GoTo Form_Load_Err
      
      DoCmd.ShowToolbar "ribbon", acToolbarNo
      
      Cleanup:
      Exit Sub
      Form_Load_Err:
      Select Case Err.Number
      Case 3044
      Beep
      MsgBox "You must be connected to the Network or the County VPN to open Contrax™! Once you are connected, try opening Contrax™ again.", vbCritical, "Not Connected to Network"
      Application.Quit acQuitSaveNone
      Case 2950
      Beep
      MsgBox "You will need to enable content prior to logging in to Contrax™ for the first time from this file location. Close the login box, then click the 'Enable Content' box at the top of the screen. After this, you should not have to do this again when opening Contrax™ from this location", vbCritical, "Enable Content Upon First Login"
      DoCmd.Close frmLogin
      Case Else
      Beep
      MsgBox "There is a problem opening Contrax™. Contact the administrator for help.", vbCritical, "Contrax™ Not Available"
      Application.Quit acQuitSaveNone
      End Select
      
      Resume Cleanup
      
      End Sub
    2. Once enabled, the user can click the login button to load the login form, which then activates the sequence of opening the forms for use.
So what kind of macros are considered safe before content is enabled? I really need that toolbar to hide.
View attachment 92106
Thanks!
First, let me ask and confirm something. The simplest approach is to deploy an ACCDR. Is that not possible in your case?
 

mistyinca1970

Member
Local time
Yesterday, 19:17
Joined
Mar 17, 2021
Messages
117
First, let me ask and confirm something. The simplest approach is to deploy an ACCDR. Is that not possible in your case?
Well...I don't know what that is... This is the first time I'm distributing my work.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:17
Joined
Oct 29, 2018
Messages
21,453
Well...I don't know what that is... This is the first time I'm distributing my work.
Basically, you simply give them a file with a file extension of ACCDR or accdr. Do you distribute ACCDE or ACCDB files?
 

mistyinca1970

Member
Local time
Yesterday, 19:17
Joined
Mar 17, 2021
Messages
117
Basically, you simply give them a file with a file extension of ACCDR or accdr. Do you distribute ACCDE or ACCDB files?
They are accdb files. Is it just a matter of changing the file extension?
 

mistyinca1970

Member
Local time
Yesterday, 19:17
Joined
Mar 17, 2021
Messages
117
Yes! Give it a try and let us know if that will work for you or not.
That works, and I'm able to click "Open" on it and the on load works after that. However; I find that after the first time, subsequent openings it still pops up the "Microsoft Access Security Notice". Is there a way to make it not do that after the first opening?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:17
Joined
Oct 29, 2018
Messages
21,453
That works, and I'm able to click "Open" on it and the on load works after that. However; I find that after the first time, subsequent openings it still pops up the "Microsoft Access Security Notice". Is there a way to make it not do that after the first opening?
Normally, I think it would stop asking afterwards, but I find that in some government networks, that's not the case (since they don't [want to] trust anyone).

So, the next option is maybe add some code to add the db folder into the Trusted Locations settings.

Or, like I said, go back to using an Autoexec macro and either show the reminder to enable content or otherwise open the main form.
 

Users who are viewing this thread

Top Bottom