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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbOKCancel - Not Working Like Expected

Status
Not open for further replies.

ddevil

Technical User
Feb 14, 2006
49
0
0
US
I'm stuggling with how to know what the user pressed with the vbOKCancel message box. I thought that vbOK was 1 and vbCancel was 2, but no matter what I select 1 is always the value.


Private Sub GetDataBtn_Click()

If Saved = 1 Then

On Error GoTo Err_GetDataBtn_Click

DoCmd.SetWarnings False

Dim stDocName1 As String

stDocName1 = "DeleteTempRefundRecord"
DoCmd.OpenQuery stDocName1, acNormal, acEdit


DoCmd.Close acForm, "RefundableForm"
DoCmd.OpenForm "CriteriaForm"

Else


MsgBox "Click Cancel to save the record or OK to continue without saving", vbOKCancel, "Record was NOT saved"

If vbOK = 1 Then (Always hits this line because vbOK = 1, what is the value when pushing the OK button?)

DoCmd.SetWarnings False

Dim stDocName2 As String

stDocName2 = "DeleteTempRefundRecord"
DoCmd.OpenQuery stDocName2, acNormal, acEdit


DoCmd.Close acForm, "RefundableForm"
DoCmd.OpenForm "CriteriaForm"

Else ' If vbCancel is selected
GoTo 1: ' Stop
End If

End If


Exit_GetDataBtn_Click:
Exit Sub

Err_GetDataBtn_Click:
MsgBox Err.Description
Resume Exit_GetDataBtn_Click
1
End Sub
 
Replace this:
MsgBox "Click Cancel to save the record or OK to continue without saving", vbOKCancel, "Record was NOT saved"
If vbOK = 1 Then
with this:
If MsgBox("Click Cancel to save the record or OK to continue without saving", vbOKCancel, "Record was NOT saved") = vbOK Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You were comparing a constant to a constant. Saying

If vbOk = 1 Then

is the same as saying

If 1 = 1 Then



 
If you need to check the result several times, then i would use

response=msgbox(.....)
if response = 1 then
...

Where response is 1 for OK and 2 for cancel.

[pc]

Graham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top