Solved

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

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

Independent Software Vendors: 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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

691 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