A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Adding a MsgBox when criteria are true



 
 
Thread Tools Display Modes
  #1  
Old April 29th, 2008, 03:54 PM posted to microsoft.public.access.forms
Gabriella777_2
external usenet poster
 
Posts: 65
Default Adding a MsgBox when criteria are true

I have a a form that contains 2 text boxes that are not used every time the
form is used. However, if the first box is used the second must be used. So
do I create a MsgBox to pop up based on an if then equation(?)?
The end result would be that when the user exits the second text box
(OnExit) it would look at the previous box and determine if the default value
($0.00) was changed (always a 0 amount). If yes, and the exited text box
is still empty, then put up a pop up to remind that it must be filled in.
Does that makes sense or is there an easier way?
--
Thanks and God bless you and yours,
Gabriella777_2

  #2  
Old April 29th, 2008, 04:31 PM posted to microsoft.public.access.forms
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default Adding a MsgBox when criteria are true

Since it's possible that they might not actually tab through the second
textbox, I'd recommend putting the logic in the form's BeforeUpdate Event:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Textbox1 0 And IsNull(Me.Textbox2) = True Then
MsgBox "You must provide a value for both Textbox1 and Textbox2"
Cancel = True
End If

End Sub

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Gabriella777_2" wrote in message
...
I have a a form that contains 2 text boxes that are not used every time the
form is used. However, if the first box is used the second must be used.
So
do I create a MsgBox to pop up based on an if then equation(?)?
The end result would be that when the user exits the second text box
(OnExit) it would look at the previous box and determine if the default
value
($0.00) was changed (always a 0 amount). If yes, and the exited text
box
is still empty, then put up a pop up to remind that it must be filled in.
Does that makes sense or is there an easier way?
--
Thanks and God bless you and yours,
Gabriella777_2



  #3  
Old April 29th, 2008, 07:43 PM posted to microsoft.public.access.forms
Gabriella777_2
external usenet poster
 
Posts: 65
Default Adding a MsgBox when criteria are true

Okay, I did as you suggested and it worked accept . . .
1. I got a pop up saying I can't go to the specified record after clicking
on the command button I created to go to the next record.
2. When I clicked the Close Form command button, I got the msgbox but after
clicking okay it closed the form anyway.
I added a SetFocus line to what you had me put in, with it setting Textbox 2
as the focus. That worked on the next record button but not on the close form
button.
--
Thanks and God bless you and yours,
Gabriella777_2



"Douglas J. Steele" wrote:

Since it's possible that they might not actually tab through the second
textbox, I'd recommend putting the logic in the form's BeforeUpdate Event:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Textbox1 0 And IsNull(Me.Textbox2) = True Then
MsgBox "You must provide a value for both Textbox1 and Textbox2"
Cancel = True
End If

End Sub

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Gabriella777_2" wrote in message
...
I have a a form that contains 2 text boxes that are not used every time the
form is used. However, if the first box is used the second must be used.
So
do I create a MsgBox to pop up based on an if then equation(?)?
The end result would be that when the user exits the second text box
(OnExit) it would look at the previous box and determine if the default
value
($0.00) was changed (always a 0 amount). If yes, and the exited text
box
is still empty, then put up a pop up to remind that it must be filled in.
Does that makes sense or is there an easier way?
--
Thanks and God bless you and yours,
Gabriella777_2




  #4  
Old April 29th, 2008, 07:47 PM posted to microsoft.public.access.forms
Gabriella777_2
external usenet poster
 
Posts: 65
Default Adding a MsgBox when criteria are true

Okay I put the code in the text box 2 OnExit rather than the form and it
worked perfectly. Just what I wanted it to do!
Thanks for the help!
--
Thanks and God bless you and yours,
Gabriella777_2



"Douglas J. Steele" wrote:

Since it's possible that they might not actually tab through the second
textbox, I'd recommend putting the logic in the form's BeforeUpdate Event:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Textbox1 0 And IsNull(Me.Textbox2) = True Then
MsgBox "You must provide a value for both Textbox1 and Textbox2"
Cancel = True
End If

End Sub

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Gabriella777_2" wrote in message
...
I have a a form that contains 2 text boxes that are not used every time the
form is used. However, if the first box is used the second must be used.
So
do I create a MsgBox to pop up based on an if then equation(?)?
The end result would be that when the user exits the second text box
(OnExit) it would look at the previous box and determine if the default
value
($0.00) was changed (always a 0 amount). If yes, and the exited text
box
is still empty, then put up a pop up to remind that it must be filled in.
Does that makes sense or is there an easier way?
--
Thanks and God bless you and yours,
Gabriella777_2




  #5  
Old April 29th, 2008, 07:50 PM posted to microsoft.public.access.forms
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default Adding a MsgBox when criteria are true

You must correct the error before you can proceed. If you decide you don't
want to save the erroneous record, hit the Esc key (you might have to hit it
twice).

It just occurred to me that the following would be safer:

If Nz(Me.Textbox1, 0) 0 And IsNull(Me.Textbox2) = True Then


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Gabriella777_2" wrote in message
...
Okay, I did as you suggested and it worked accept . . .
1. I got a pop up saying I can't go to the specified record after clicking
on the command button I created to go to the next record.
2. When I clicked the Close Form command button, I got the msgbox but
after
clicking okay it closed the form anyway.
I added a SetFocus line to what you had me put in, with it setting Textbox
2
as the focus. That worked on the next record button but not on the close
form
button.
--
Thanks and God bless you and yours,
Gabriella777_2



"Douglas J. Steele" wrote:

Since it's possible that they might not actually tab through the second
textbox, I'd recommend putting the logic in the form's BeforeUpdate
Event:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Textbox1 0 And IsNull(Me.Textbox2) = True Then
MsgBox "You must provide a value for both Textbox1 and Textbox2"
Cancel = True
End If

End Sub

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Gabriella777_2" wrote in
message
...
I have a a form that contains 2 text boxes that are not used every time
the
form is used. However, if the first box is used the second must be
used.
So
do I create a MsgBox to pop up based on an if then equation(?)?
The end result would be that when the user exits the second text box
(OnExit) it would look at the previous box and determine if the default
value
($0.00) was changed (always a 0 amount). If yes, and the exited text
box
is still empty, then put up a pop up to remind that it must be filled
in.
Does that makes sense or is there an easier way?
--
Thanks and God bless you and yours,
Gabriella777_2






 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:04 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.