PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

Msgbox cancel button

 
 
stoehrkr@gmail.com
Guest
Posts: n/a
 
      15th Jun 2007
Hello!

I'm fairly new to Access and VB and I've been getting along alright
but I've run into a problem with a message box I set up in my form.

Situation: the field FvsNF will always be filled out. Depending on
the answer (yes or no) certain fields become enabled or disabled. The
problem is if a user decides to change their answer for FvsNF after
filling out the wrong fields. The incorrect fields need to go back to
zero if they decide to proceed with that action. However if they
don't want to proceed I want to give them an out without losing their
entries. The code I have now is:

Private Sub FvsNF_BeforeUpdate(Cancel As Integer)
Result = MsgBox("Warning: All values in section will become zero.",
vbOKCancel)
If vbOK Then
TotalCC.Value = 0
OSCC.Value = 0
Clumpiness.Value = 0
ClumpDensity.Value = 0
ClumpSize.Value = 0
CrownDiff.Value = 0
CanopyLayers.Value = 0
Logging.Value = 0
pcc.Value = 0
DensOS.Value = -99
DensUS.Value = -99
sizeOS.Value = 0
sizeUS.Value = 0
sppOS.Value = 0
sppUS.Value = 0
Nonforesttype.Value = 0
ElevBelt.Value = 0
nonforestsppOS.Value = 0
nonforestOSCC.Value = 0
treecovergstype.Value = 0
Else

End If
End Sub

I've tried a lot of things under Else...and lots of different
combinations but I can't seem to get the cancel button to cancel! Any
help would be greatly appreciated!

Kali

 
Reply With Quote
 
 
 
 
ruralguy via AccessMonster.com
Guest
Posts: n/a
 
      15th Jun 2007
Me.UnDo will return all of the controls to the values last saved.

(E-Mail Removed) wrote:
>Hello!
>
>I'm fairly new to Access and VB and I've been getting along alright
>but I've run into a problem with a message box I set up in my form.
>
>Situation: the field FvsNF will always be filled out. Depending on
>the answer (yes or no) certain fields become enabled or disabled. The
>problem is if a user decides to change their answer for FvsNF after
>filling out the wrong fields. The incorrect fields need to go back to
>zero if they decide to proceed with that action. However if they
>don't want to proceed I want to give them an out without losing their
>entries. The code I have now is:
>
>Private Sub FvsNF_BeforeUpdate(Cancel As Integer)
>Result = MsgBox("Warning: All values in section will become zero.",
>vbOKCancel)
> If vbOK Then
> TotalCC.Value = 0
> OSCC.Value = 0
> Clumpiness.Value = 0
> ClumpDensity.Value = 0
> ClumpSize.Value = 0
> CrownDiff.Value = 0
> CanopyLayers.Value = 0
> Logging.Value = 0
> pcc.Value = 0
> DensOS.Value = -99
> DensUS.Value = -99
> sizeOS.Value = 0
> sizeUS.Value = 0
> sppOS.Value = 0
> sppUS.Value = 0
> Nonforesttype.Value = 0
> ElevBelt.Value = 0
> nonforestsppOS.Value = 0
> nonforestOSCC.Value = 0
> treecovergstype.Value = 0
> Else
>
> End If
>End Sub
>
>I've tried a lot of things under Else...and lots of different
>combinations but I can't seem to get the cancel button to cancel! Any
>help would be greatly appreciated!
>
>Kali


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200706/1

 
Reply With Quote
 
 
 
 
Guy
Guest
Posts: n/a
 
      16th Jun 2007
Kali,

I assume you meant:

If Result = vbOK then
' Do something
Else
' Do something else
End If

Or you can combine it in the If statement such as:

If MsgBox("Warning: All values in section will become zero.", vbOKCancel) =
vbOK then
' Do something
Else
' Do something else
End If

Or if you have more options you can also use the Select Case as in:

Select Case MsgBox("Do you really want to do this?", vbYesNoCancel +
vbQuestion, "Do this Confirmation")
Case vbYes:
' Yes - Do something
Case vbNo:

' No -Do something
Case Else

' Cancel - Do something
End Select

Or

Select Case MsgBox("Do you really want to do this?", vbYesNoCancel +
vbQuestion, "Do this Confirmation")
Case vbYes:
' Yes - Do something
Case vbNo:

' No -Do something
Case Cancel

' Cancel - Do something
Case Else
(Note. this action should never be taken for the above statement, but it
is generally good practice to include an Else for more complex scenarios)
' Else - Do something
End Select

Of course Me.Undo will also work, if returning to your last set of saved
values is your intention.

Hope this helps
Guy

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello!
>
> I'm fairly new to Access and VB and I've been getting along alright
> but I've run into a problem with a message box I set up in my form.
>
> Situation: the field FvsNF will always be filled out. Depending on
> the answer (yes or no) certain fields become enabled or disabled. The
> problem is if a user decides to change their answer for FvsNF after
> filling out the wrong fields. The incorrect fields need to go back to
> zero if they decide to proceed with that action. However if they
> don't want to proceed I want to give them an out without losing their
> entries. The code I have now is:
>
> Private Sub FvsNF_BeforeUpdate(Cancel As Integer)
> Result = MsgBox("Warning: All values in section will become zero.",
> vbOKCancel)
> If vbOK Then
> TotalCC.Value = 0
> OSCC.Value = 0
> Clumpiness.Value = 0
> ClumpDensity.Value = 0
> ClumpSize.Value = 0
> CrownDiff.Value = 0
> CanopyLayers.Value = 0
> Logging.Value = 0
> pcc.Value = 0
> DensOS.Value = -99
> DensUS.Value = -99
> sizeOS.Value = 0
> sizeUS.Value = 0
> sppOS.Value = 0
> sppUS.Value = 0
> Nonforesttype.Value = 0
> ElevBelt.Value = 0
> nonforestsppOS.Value = 0
> nonforestOSCC.Value = 0
> treecovergstype.Value = 0
> Else
>
> End If
> End Sub
>
> I've tried a lot of things under Else...and lots of different
> combinations but I can't seem to get the cancel button to cancel! Any
> help would be greatly appreciated!
>
> Kali
>



 
Reply With Quote
 
stoehrkr@gmail.com
Guest
Posts: n/a
 
      18th Jun 2007
Hmmm...
Thank you for the suggestions but I'm still having problems. I think
I need what the "do something" code is for making it cancel because I
can't make my code do anything but return all of the values to zero no
matter which button I choose (OK or Cancel).

Could I be doing something wrong with Me.undo? It doesn't seem to be
doing anything at the moment.

I'll keep playing around with it but if you have any other suggestions
I'm all ears!

Thanks again,
Kali

 
Reply With Quote
 
ruralguy via AccessMonster.com
Guest
Posts: n/a
 
      18th Jun 2007
Have you single stepped the code to make sure it is executing? Me.UnDo is
useless after you have saved the record. What values are in the table that
the controls should return to. If the controls are *not* bound to fields in
the underlying table/query then Me.UnDo will not work.

(E-Mail Removed) wrote:
>Hmmm...
>Thank you for the suggestions but I'm still having problems. I think
>I need what the "do something" code is for making it cancel because I
>can't make my code do anything but return all of the values to zero no
>matter which button I choose (OK or Cancel).
>
>Could I be doing something wrong with Me.undo? It doesn't seem to be
>doing anything at the moment.
>
>I'll keep playing around with it but if you have any other suggestions
>I'm all ears!
>
>Thanks again,
>Kali


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200706/1

 
Reply With Quote
 
stoehrkr@gmail.com
Guest
Posts: n/a
 
      18th Jun 2007

Yes, I figured out that I need it to return to the values the user has
just entered not the ones that were last saved (It was returning to
zero which was the last saved record. It confused me at the time). I
got it to work by using FvsNF.undo, it keeps the last values but
unfortunately it still switches the focus and enables the wrong set of
options for a user who canceled.

 
Reply With Quote
 
stoehrkr@gmail.com
Guest
Posts: n/a
 
      18th Jun 2007
Alright- I'm deleting my message box and hoping the user of this form
know's what they're doing...they'll learn quickly if they don't!
Thanks to all for your help!
Kali

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a cancel button to MsgBox Chad Microsoft Access Getting Started 2 26th Mar 2008 07:31 AM
MsgBox Cancel Button Question =?Utf-8?B?TUphdEFmbGFj?= Microsoft Access VBA Modules 7 7th May 2007 01:21 PM
Cancel button to cancel the whole macro excelnut1954 Microsoft Excel Programming 5 17th Jan 2006 09:27 PM
vbscript msgbox confirmation when user clicks Cancel button Bucky Microsoft ASP .NET 1 19th May 2005 10:17 PM
Cancel button to bypass MsgBox Myrna Rodriguez Microsoft Excel Programming 3 2nd Jun 2004 09:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:45 PM.