?
Solved

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

Posted on 2010-09-10
3
Medium Priority
?
506 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 1000 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

801 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