Solved

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

Posted on 2010-09-10
3
473 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
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

786 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