Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use Msbox for a value in sub... 3

Status
Not open for further replies.

realstandman

IS-IT--Management
Oct 29, 2003
87
US
Ok I am using a button on a form to exit the form. I have validation in place and would like to ask the user if they want to save the record before exiting. Here is what I have so far. The Validation works but it skips past the message box code. I am new to this so you may be able to get the direction I am goin in on this. Thanks,

Code:
Private Sub cmdExit_Click()
    
    If validateClaimsProcessedRecord = False Then
    
        Dim exitvalue As String
    
        exitvalue = MsgBox("Would you like to save this Record?", vbYesNo)
                        
            If exitvalue = "vbyes" Then
                        
            DoCmd.Save
            
            Else
            
            Exit Sub
            
            End If
                
       Exit Sub
    End If
    
    DoCmd.RunMacro ("mcrExit.CloseClaimsProcessedExaminer")
    
End Sub

Don't think and the solution will come.
 
vbYes is not text, all of the vbThings return a number, as far as I can remember, so:

[tt]If exitvalue = vbyes Then
'You will find that the record is saved by default,
'so you will have to unsave it, rather than save it.
Else
Me.Undo
'Which won't work properly if you have a subform.
End if[/tt]

You may wish to look at the Before Update event for the form.

 
So How can I find out what numeric value it returns?

Thanks,

Don't think and the solution will come.
 

This one works for me.


Dim intReturn As Integer
intReturn = MsgBox("Would you like to save this record?", vbYesNo + vbDefaultButton3, "Save changes?")
Select Case intReturn
Case vbYes
'Do Nothing
Case vbNo
Me.Undo
End Select
 
Hi!

Just say:

If MsgBox(etc) = vbYes Then
DoCmd.Save
Else
Me.Undo
End If

In your original post you said that it was skipping the message box code. Does the message box even pop up?

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
No the message box never poped up?

stan

Don't think and the solution will come.
 
realstandman

I posted a short example. There is no need to know what number it returns, just don't put vbThingies in quotes, they are, after a fashion, mnemonics. However, you can type ?vbThingy in the immediate window or look in the Object Browser, if you want to see what number is represented (vbYes = 6).
 
Cool, Gotcha.. Thanks, I'm just trying to get the user to save the page if they havn't already before exiting the form. It does do a check to validate the data and if it passes validation I need to give a pop up to save. I just can't get the popup to work.

Thanks, Stan

Don't think and the solution will come.
 
Hi!

If the message box isn't popping up then validateClaimsProcessedRecord isn't returning false when you think it should. Is it possible that you want to run this code when validateClaimsProcessedRecord returns true?



Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
How are ya realstandman . . .

just another version . . .
Code:
[blue]   Dim Msg As String, Style As Integer, Title As String
   
   If validateClaimsProcessedRecord = False Then
      Msg = "Would you like to save this Record?"
      Style = vbQuestion + vbYesNo
      Title = "User Decision required! . . ."
      
      If MsgBox(Msg, Style, Title) = vbYes Then
         DoCmd.RunCommand acCmdSaveRecord
      End If
   Else
      [green]'Code validation true[/green]
      Exit Sub
   End If
   
   DoCmd.RunMacro ("mcrExit.CloseClaimsProcessedExaminer")[/blue]

Calvin.gif
See Ya! . . . . . .
 
Cool thanks everyone TheAceMan1's worked out fine.....



Don't think and the solution will come.
 
Code:
MsgBox Arguments
Constant Value Description 

vbOKOnly 0 OK button only (default) 
vbOKCancel 1 OK and Cancel buttons 
vbAbortRetryIgnore 2 Abort, Retry, and Ignore buttons 
vbYesNoCancel 3 Yes, No, and Cancel buttons 
vbYesNo 4 Yes and No buttons 
vbRetryCancel 5 Retry and Cancel buttons 
vbCritical 16 Critical message 
vbQuestion 32 Warning query 
vbExclamation 48 Warning message 
vbInformation 64 Information message 
vbDefaultButton1 0 First button is default (default) 
vbDefaultButton2 256 Second button is default 
vbDefaultButton3 512 Third button is default 
vbDefaultButton4 768 Fourth button is default 
vbApplicationModal 0 Application modal message box (default) 
vbSystemModal 4096 System modal message box 
vbMsgBoxHelpButton 16384 Adds Help button to the message box 
VbMsgBoxSetForeground 65536 Specifies the message box window as the foreground window 
vbMsgBoxRight 524288 Text is right aligned 
vbMsgBoxRtlReading 1048576 Specifies text should appear as right-to-left reading on Hebrew and Arabic systems 



MsgBox Return Values
Constant Value Description 

vbOK 1 OK button pressed 
vbCancel 2 Cancel button pressed 
vbAbort 3 Abort button pressed 
vbRetry 4 Retry button pressed 
vbIgnore 5 Ignore button pressed 
vbYes 6 Yes button pressed 
vbNo 7 No button pressed
 
Howdy Remou . . .

When my kids were younger they use to always say:
MyKids said:
[blue]I'm rubber and your glue . . . What ever you say, bounces off of me and sticks to you![/blue]
A [blue]deserving star[/blue] for you as well! . . .

Calvin.gif
See Ya! . . . . . .
 
realstandman . . .

Although you can [blue]convert macro's to VBA[/blue], I'm suggesting you get away from macro's (which are all but lost) and learn more of VBA. [blue]I promise you'll never go back unless its a special circumstance, which will be rare![/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top