Solved

vba code to open a message box (yes/no) when an Access database opens

Posted on 2010-09-10
3
484 Views
Last Modified: 2013-11-29
I would like help, using vba, to open a message box (yes/no) when the user opens an Access database.  I would prefer that this message box appear before the main database window becomes visible (I am not sure if this is possible).  Anyway, once the message box opens, the user clicks on yes and the message box disappears and the main database window opens.  If the user clicks no, then the database closes.  The title on the message box header should read "CAUTION".  The actual message should read "TEST".  Thank for the expert(s) help.
0
Comment
Question by:sxxgupta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 250 total points
ID: 33645485
1. create a macro and save as AutoExec
 
Action
RunCode


Function Name Startup()

2. in a regular module place the function

Function StartUp()
If (MsgBox("TEST", vbYesNo, "CAUTION")) = vbYes Then
    DoCmd.OpenForm "MainForm"
    Else
    DoCmd.Quit
End If
End Function
0
 
LVL 14

Assisted Solution

by:Bill Ross
Bill Ross earned 250 total points
ID: 33645503
Hi,

You need 2 things.  1 is the code and 2 an AutoExec macro to run it.  Here are the steps:

Step 1 - Create a new module
Paste the code between the *** (don't include them) into it to create a new procedure called TestMessage:

***
Public Function TestMessage()
    Dim v
    v = MsgBox("test", vbCritical + vbYesNo, "CAUTION")
    If v = vbNo Then
        DoCmd.Quit
    End If
End Function
***


Save the module as Module1

Step 2 - Create a new macro

Action:  RunCode
Function Name: TestMessage()

Important - You must save this macro as the name AutoExec.  This will run it at startup.

Regards,

Bill
0
 

Author Closing Comment

by:sxxgupta
ID: 33646182
Thank you both.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question