Run VBA on database startup

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The myStartup function is working when I run from VBA editor but as you might
guess I want to run this from Startup. I did this by making a AUTOEXEC macro
which calls the myStartup Function. It returns an error when the VB response
is NO becuasse the macro is Halted.

How do I either

a) Run the VBA directly from code on stratup (no AUTOEXEC macro)

or

b) Remove the halt error from the macro. (n.b. After statup is complete
warnings should be set to on.)

Bruce



Option Compare Database

Function myStartup()

myYesNo ("Do you wish to update the current product list?")
Call set_curr_Products
MsgBox ("Current Product List Updated")

End Function

Function myYesNo(myString As String)

myYesNo = MsgBox(myString, vbYesNo, "Price Database")
If myYesNo = vbNo Then
MsgBox ("Cancelled")
End
End If

End Function
 
a) Run the VBA directly from code
on stratup (no AUTOEXEC macro)

Put the code in the Open or Load event of a Form. On the database window,
Tools | Startup, and specify that Form is the startup form.

Larry Linson
Microrosft Access MVP
 
The error comes when you hit the END statement in your myYesNo function.
This stops all running code dead in the water. I think you should use
the return value of myYesNo in an IF structure:

Option Compare Database

Function myStartup()

If myYesNo("Do you wish to update ... ?") = vbYes Then
Call set_curr_Products
MsgBox ("Current Product List Updated")
End If

End Function

Function myYesNo(myString As String) As Long

myYesNo = MsgBox(myString, vbYesNo, "Price Database")
If myYesNo = vbNo Then
MsgBox ("Cancelled")
End If

End Function



HTH,
 
Back
Top