|
 |
access thread: vbYesNo in Access?
Message #1 by "Ryan Lockhart" <rlockhart@p...> on Mon, 26 Nov 2001 18:31:38
|
|
I am trying to use the MsgBox function to return True/False, which I have
done before in Visual Basic. Is this possible with VBA? Here is my code
Dim yesNo As Boolean
yesNo = MsgBox("Have you changed the Print margins to .5?",_
vbYesNo, "Print Margins")
If yesNo = False Then
Exit Sub
Else: DoCmd.PrintOut acPrintAll
Message #2 by "Joseph N. Stackhouse" <joe@s...> on Mon, 26 Nov 2001 13:32:20 -0500
|
|
Do it this way,
Dim YesNo
YesNo = MsgBox("Have you changed the Print margins to .5?", vbYesNo,
"Print Margins")
If YesNo = VbNo Then
Exit Sub
Else
DoCmd.PrintOut acPrintAll
-Joe
-----Original Message-----
From: Ryan Lockhart [mailto:rlockhart@p...]
Sent: Monday, November 26, 2001 6:32 PM
To: Access
Subject: [access] vbYesNo in Access?
I am trying to use the MsgBox function to return True/False, which I
have
done before in Visual Basic. Is this possible with VBA? Here is my
code
Dim yesNo As Boolean
yesNo = MsgBox("Have you changed the Print margins to .5?",_ vbYesNo,
"Print Margins")
If yesNo = False Then
Exit Sub
Else: DoCmd.PrintOut acPrintAll
---
You are currently subscribed to access as: joe@s... To
unsubscribe send a blank email to $subst('Email.Unsub')
Message #3 by "John Ruff" <papparuff@c...> on Mon, 26 Nov 2001 10:39:44 -0800
|
|
Or you can do it this way
If MsgBox("Have you changed the Print margins to .5?", vbYesNo, "Print
Margins")=vbNo then
Exit Sub
Else
DoCmd.PrintOut acPrintAll
Endif
John Ruff - The Eternal Optimist :-)
-----Original Message-----
From: Joseph N. Stackhouse [mailto:joe@s...]
Sent: Monday, November 26, 2001 10:32 AM
To: Access
Subject: [access] RE: vbYesNo in Access?
Do it this way,
Dim YesNo
YesNo = MsgBox("Have you changed the Print margins to .5?", vbYesNo,
"Print Margins")
If YesNo = VbNo Then
Exit Sub
Else
DoCmd.PrintOut acPrintAll
-Joe
-----Original Message-----
From: Ryan Lockhart [mailto:rlockhart@p...]
Sent: Monday, November 26, 2001 6:32 PM
To: Access
Subject: [access] vbYesNo in Access?
I am trying to use the MsgBox function to return True/False, which I
have
done before in Visual Basic. Is this possible with VBA? Here is my
code
Dim yesNo As Boolean
yesNo = MsgBox("Have you changed the Print margins to .5?",_ vbYesNo,
"Print Margins")
If yesNo = False Then
Exit Sub
Else: DoCmd.PrintOut acPrintAll
---
You are currently subscribed to access as: joe@s... To
unsubscribe send a blank email to $subst('Email.Unsub')
---
You are currently subscribed to access as: papparuff@c... To
unsubscribe send a blank email to $subst('Email.Unsub')
Message #4 by "Ryan Lockhart" <rlockhart@p...> on Mon, 26 Nov 2001 19:08:13
|
|
Thank you. That did it.
> Or you can do it this way
>
> If MsgBox("Have you changed the Print margins to .5?", vbYesNo, "Print
> Margins")=vbNo then
>
> Exit Sub
> Else
> DoCmd.PrintOut acPrintAll
> Endif
>
> John Ruff - The Eternal Optimist :-)
>
>
>
> -----Original Message-----
> From: Joseph N. Stackhouse [mailto:joe@s...]
> Sent: Monday, November 26, 2001 10:32 AM
> To: Access
> Subject: [access] RE: vbYesNo in Access?
>
>
> Do it this way,
>
> Dim YesNo
> YesNo = MsgBox("Have you changed the Print margins to .5?", vbYesNo,
> "Print Margins")
> If YesNo = VbNo Then
> Exit Sub
> Else
> DoCmd.PrintOut acPrintAll
>
> -Joe
>
> -----Original Message-----
> From: Ryan Lockhart [mailto:rlockhart@p...]
> Sent: Monday, November 26, 2001 6:32 PM
> To: Access
> Subject: [access] vbYesNo in Access?
>
>
> I am trying to use the MsgBox function to return True/False, which I
> have
> done before in Visual Basic. Is this possible with VBA? Here is my
> code
>
> Dim yesNo As Boolean
> yesNo = MsgBox("Have you changed the Print margins to .5?",_ vbYesNo,
> "Print Margins")
> If yesNo = False Then
> Exit Sub
> Else: DoCmd.PrintOut acPrintAll
> ---
> You are currently subscribed to access as: joe@s... To
> unsubscribe send a blank email to $subst('Email.Unsub')
>
>
>
> ---
> You are currently subscribed to access as: papparuff@c... To
> unsubscribe send a blank email to $subst('Email.Unsub')
>
>
>
>
Message #5 by "Rand E. Gerald" <rgerald@u...> on Wed, 28 Nov 2001 15:45:18
|
|
> Or you can do it this way
>
> If MsgBox("Have you changed the Print margins to .5?", vbYesNo, "Print
> Margins")=vbNo then
>
> Exit Sub
> Else
> DoCmd.PrintOut acPrintAll
> Endif
>
> John Ruff - The Eternal Optimist :-)
>
>
>
> -----Original Message-----
> From: Joseph N. Stackhouse [mailto:joe@s...]
> Sent: Monday, November 26, 2001 10:32 AM
> To: Access
> Subject: [access] RE: vbYesNo in Access?
>
>
> Do it this way,
>
> Dim YesNo
> YesNo = MsgBox("Have you changed the Print margins to .5?", vbYesNo,
> "Print Margins")
> If YesNo = VbNo Then
> Exit Sub
> Else
> DoCmd.PrintOut acPrintAll
>
> -Joe
>
> -----Original Message-----
> From: Ryan Lockhart [mailto:rlockhart@p...]
> Sent: Monday, November 26, 2001 6:32 PM
> To: Access
> Subject: [access] vbYesNo in Access?
>
>
> I am trying to use the MsgBox function to return True/False, which I
> have
> done before in Visual Basic. Is this possible with VBA? Here is my
> code
>
> Dim yesNo As Boolean
> yesNo = MsgBox("Have you changed the Print margins to .5?",_ vbYesNo,
> "Print Margins")
> If yesNo = False Then
> Exit Sub
> Else: DoCmd.PrintOut acPrintAll
> ---
> You are currently subscribed to access as: joe@s... To
> unsubscribe send a blank email to $subst('Email.Unsub')
>
>
>
> ---
> You are currently subscribed to access as: papparuff@c... To
> unsubscribe send a blank email to $subst('Email.Unsub')
>
>
>
>
Message #6 by "Rand E. Gerald" <rgerald@u...> on Wed, 28 Nov 2001 16:10:13
|
|
> > Or you can do it this way
> >
> > If MsgBox("Have you changed the Print margins to .5?", vbYesNo, "Print
> > Margins")=vbNo then
> >
> > Exit Sub
> > Else
> > DoCmd.PrintOut acPrintAll
> > Endif
> >
> > John Ruff - The Eternal Optimist :-)
> >
> >
> >
> > -----Original Message-----
> > From: Joseph N. Stackhouse [mailto:joe@s...]
> > Sent: Monday, November 26, 2001 10:32 AM
> > To: Access
> > Subject: [access] RE: vbYesNo in Access?
> >
> >
> > Do it this way,
> >
> > Dim YesNo
> > YesNo = MsgBox("Have you changed the Print margins to .5?", vbYesNo,
> > "Print Margins")
> > If YesNo = VbNo Then
> > Exit Sub
> > Else
> > DoCmd.PrintOut acPrintAll
> >
> > -Joe
> >
> > -----Original Message-----
> > From: Ryan Lockhart [mailto:rlockhart@p...]
> > Sent: Monday, November 26, 2001 6:32 PM
> > To: Access
> > Subject: [access] vbYesNo in Access?
> >
> >
> > I am trying to use the MsgBox function to return True/False, which I
> > have
> > done before in Visual Basic. Is this possible with VBA? Here is my
> > code
> >
> > Dim yesNo As Boolean
> > yesNo = MsgBox("Have you changed the Print margins to .5?",_ vbYesNo,
> > "Print Margins")
> > If yesNo = False Then
> > Exit Sub
> > Else: DoCmd.PrintOut acPrintAll
> > ---
> > You are currently subscribed to access as: joe@s... To
> > unsubscribe send a blank email to $subst('Email.Unsub')
> >
> >
> >
> > ---
> > You are currently subscribed to access as: papparuff@c... To
> > unsubscribe send a blank email to $subst('Email.Unsub')
> >
> >
> >
> >
Oops I forgot to add my comments!
MsgBox returns an integer value based upon the buttons available and
pressed.
vbOk = 1 Ok button
vbCancel = 2 Cancel button or Esc Key
vbAbort = 3 Abort button
vbRetry = 4 Retry button
vbIgnore = 5 Ignore Button
vbYes = 6 Yes button
vbNo = 7 No button
Therefore to get a True/False result you must code it like this:
Dim YesNo as Boolean
yesNo = (vbYes = MsgBox("Press Yes for True No for False",vbYesNo))
If yesNo Then
debug.print "True"
Else
debug.print "False"
End If
Message #7 by "Yehuda Rosenblum" <Yehuda@I...> on Wed, 28 Nov 2001 11:12:08 -0500
|
|
Alternatively you could do:
Dim intRet as integer
intRet =3D MsgBox("Is this a question?",vbYesNO)
If intRet =3D vbYes then
'whatever
End If
-----Original Message-----
From: Rand E. Gerald [mailto:rgerald@u...]
Sent: Wednesday, November 28, 2001 11:10 AM
To: Access
Subject: [access] RE: vbYesNo in Access?
> > Or you can do it this way
> >
> > If MsgBox("Have you changed the Print margins to .5?", vbYesNo,
> > "Print Margins")=3DvbNo then
> >
> > Exit Sub
> > Else
> > DoCmd.PrintOut acPrintAll
> > Endif
> >
> > John Ruff - The Eternal Optimist :-)
> >
> >
> >
> > -----Original Message-----
> > From: Joseph N. Stackhouse [mailto:joe@s...]
> > Sent: Monday, November 26, 2001 10:32 AM
> > To: Access
> > Subject: [access] RE: vbYesNo in Access?
> >
> >
> > Do it this way,
> >
> > Dim YesNo
> > YesNo =3D MsgBox("Have you changed the Print margins to .5?",
> > vbYesNo, "Print Margins")
> > If YesNo =3D VbNo Then
> > Exit Sub
> > Else
> > DoCmd.PrintOut acPrintAll
> >
> > -Joe
> >
> > -----Original Message-----
> > From: Ryan Lockhart [mailto:rlockhart@p...]
> > Sent: Monday, November 26, 2001 6:32 PM
> > To: Access
> > Subject: [access] vbYesNo in Access?
> >
> >
> > I am trying to use the MsgBox function to return True/False, which I
> > have done before in Visual Basic. Is this possible with VBA? Here
> > is my code
> >
> > Dim yesNo As Boolean
> > yesNo =3D MsgBox("Have you changed the Print margins to .5?",_
> > vbYesNo, "Print Margins")
> > If yesNo =3D False Then
> > Exit Sub
> > Else: DoCmd.PrintOut acPrintAll
> > ---
> > You are currently subscribed to access as: joe@s... To
> > unsubscribe send a blank email to $subst('Email.Unsub')
> >
> >
> >
> > ---
> > You are currently subscribed to access as: papparuff@c... To
> > unsubscribe send a blank email to $subst('Email.Unsub')
> >
> >
> >
> >
Oops I forgot to add my comments!
MsgBox returns an integer value based upon the buttons available and
pressed.
vbOk =3D 1 Ok button
vbCancel =3D 2 Cancel button or Esc Key
vbAbort =3D 3 Abort button
vbRetry =3D 4 Retry button
vbIgnore =3D 5 Ignore Button
vbYes =3D 6 Yes button
vbNo =3D 7 No button
Therefore to get a True/False result you must code it like this:
Dim YesNo as Boolean
yesNo =3D (vbYes =3D MsgBox("Press Yes for True No for False",vbYesNo))
If yesNo Then
debug.print "True"
Else
debug.print "False"
End If
---
You are currently subscribed to access as: yehuda@i... To
unsubscribe send a blank email to $subst('Email.Unsub')
Read the future with ebooks at B&N
http://service.bfast.com/bfast/click?bfmid=3D2181&sourceid=3D38934667&cat
ego
ryid=3Drn_ebooks
Message #8 by "Gregory Serrano" <SerranoG@m...> on Thu, 29 Nov 2001 18:27:55
|
|
This way is more compact:
If MsgBox("Have you changed the Print margins to 0.5?", _
vbYesNo + vbQuestion, "Print Margins") Then
DoCmd.PrintOut acPrintAll
Else
Exit Sub
EndIf
Notes:
The vbYesNo + vbQuestion will put a typical question-asking dialog box up
and your Windows question sound event will be heard.
Putting the MsgBox function directly in the IF statement removes the need
to assign the boolean variable, freeing up some memory. Do this with
enough of these variables and you can see some considerable savings.
You don't need to say "If MsgBox(...) = vbYes Then" because depending on
your answer, the function MsgBox itself will evaluate to YES or NO (i.e.
TRUE or FALSE). Typing "If MsgBox(...) Then" will do it.
If you need to use the boolean variable YesNo somewhere else later, then
use the YesNo = Msgbox(...) / If YesNo = vbYes Then structure. One
programming convention though is to always evaluate the positive first,
then the negative. That is,
If intNumber = 0 Then 'or If YesNo = vbYes Then or If YesNo Then
Do This
Else
Do That
Endif
Avoid this:
If intNumber <> 0 Then 'or If YesNo = vbNo Then or If Not YesNo Then
Do That
Else
Do This
EndIf
Greg
|
|
 |