Solved

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

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

Accepted Solution

by:
Rey Obrero 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now