Yes/No macro problem

CraigDouglas

Registered User.
Local time
Today, 13:31
Joined
Sep 14, 2016
Messages
31
Please, can someone help me? I am using Access 2007. I want to use a macro. If a certain field IsNull I want a message to pop up and ask a question and then I want it so you can choose Yes No or Cancel or even just Yes No. The fields name is [EmailAddress] the question would be "Are you sure you want to close the form without an email address?" If Yes is chosen then I want the form to close and if No is chosen I want the form to stay open so that an email address can be added. Would I put the macro in the On Close form event?

Sincerely
Craig
 
why a macro? I am using the afterupdate events.

If isnull(me.yourfieldname) then
' do something
end if

You can also make this a sub routine and call this routine in any other field you want

Ben
 
Thank you, Ben. I was thinking of using a macro so that I could learn how to do it that way and then I wanted to convert the macro to VBA that way I could see how to do it in both. Please, Ben what would be the rest of the code you gave, the 'do something' part. Would it be something like? MsgBox("Are you sure you want to close the form without an email address?",4)=7 What other code do I need?
The email field is one field among other fields. It is part of a customers address form.
 
Form validation is best done in the forms before update property, as it allows you to cancel any edits made to any bound controls.

Do a search on here for form validation.
 
Craig,

Have you watched any youtube videos on Introduction to Access, or Introduction to Database?
You seems to be considering adjustments to the paint on a window frame but you haven't designed the house yet.
It might be better for you and readers if you could post a 5-6 line overview of the requirement in simple English.
 
You can define an exit button.
In the onclick event, you can add for example

Dim answer as long
If isnull(me.yourfieldname) then
answer = msgbox("Are you sure you want to close the form without an email address?", vbyesnocancel)
if answer = vbyes then
docmd.close
end if
end if

Ben
 
@Boerbende - That won't fire if the form is closed by any other method though.
 

Users who are viewing this thread

Back
Top Bottom