You are here:

Using MS Access/If I cannot use the Autoexec Macro...

Advertisement


Question
Hi Scott,

I have a database that I want to distribute to "Agents" around the world.

It all works perfectly on my machine, and on my brother's machine in Thailand.  However, it won't work on anyone else's machine from a clean 'drop and run' scenario, because they might not have enabled all macros on startup (Access Options-Trust Center... etc).

It has a lot to do with me creating Autoexec macro, which then runs a function AgentCheck(), to check for one thing - does the database have any agent info? (default=No):


Function AgentCheck()

   If DCount("AgentID", "TblAgents") = 0 Then
       DoCmd.OpenForm "FrmAgentInfo"
   Else
       DoCmd.OpenForm "Switchboard"
   End If
   
End Function

This enables each new agent to enter his personal and company nformation through FrmAgentInfo.   Once completed, and committed to the TblAgents, that form closes and the main menu opens up.

When the database is opened up next time, the main menu appears - as it should.

It's all great till a new agent opens the database,and it fails to work because macros are disabled, and obviously the AgentCheck() won't do it's job!

Can you suggest a way around using macro AutoExec, but still get the same result on opening the database?

The Tools-Options-Startup [open form] selection is "Switchboard", so it needs to be centred around the opening of that form.

Muchly appreciate your help :)

cheers
Pete

Answer
Sure, I rarely use an Autoexec macro (rarely use macros). You can use the On Open event of your startup form to do the same thing.

I would add this code to the On Open event:

Dim booNewAgent AS Boolean

BooNewAgent = AgentCheck


If BooNewAgent Then
      DoCmd.OpenForm "FrmAgentInfo"
      DoCmd.Close acForm, Switchboard
End If

Then change the New Agent function to:

Public Function AgentCheck() As Boolean

  If DCount("AgentID", "TblAgents") = 0 Then
      AgentCheck = True
  Else
      AgentCheck = False
  End If
  
End Function

But I think your real issue is making sure they install the app into a Trusted Location. I would look for code that will set the current folder as a Trusted location.

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Website: http://www.diamondassoc.com
Microsoft Access MVP 2007
Author: Microsoft Office Access 2007 VBA  

Using MS Access

All Answers


Answers by Expert:


Ask Experts

Volunteer


Scottgem

Expertise

I can answer almost all types of questions relating to Microsoft Access usage and application design. My strengths are database and interface design.

Experience

I've been designing databases for over 25 years working with dBase, FoxPro, Approach and Access.

Organizations
Author of Microsoft Office Access 2007 VBA
Techncial Editor for Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports & Queries From Que Publishing

Education/Credentials
Brooklyn College BA

©2016 About.com. All rights reserved.