MsgBox vbOKCancel Problem (1 Viewer)

sparkes84

Registered User.
Local time
Today, 15:20
Joined
Apr 2, 2009
Messages
16
Hello everybody.

I'm so stuck! It's most likely very simple, but I'm tearing my hair out here.

On the On Click command of a command button to open a form, I want a MsgBox to appear (which is does) and if OK is clicked, then I want it to open the Information Manager's form, else, when they click on Cancel, it stays where it is (ie, stays on the same form). However, at the moment, whether I click OK or Cancel, it goes to the Information Manager's form.

Here is my code (basic as it is!):

Private Sub Command26_Click()
On Error GoTo Err_Command26_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Information Management"

MsgBox "If you are NOT the Information Manager, then please click on Cancel", vbOKCancel, "C R I T I C A L !!"
If vbOKCancel = vbCancel Then DoCmd.Close

Else: DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Exit_Command26_Click:
Exit Sub
Err_Command26_Click:
MsgBox Err.Description
Resume Exit_Command26_Click
End Sub

Any help would be SO gratefully received.
Kind regards,
sparkes84
 

DCrake

Remembered
Local time
Today, 15:20
Joined
Jun 8, 2005
Messages
8,626
Code:
If MsgBox ("If you are NOT the Information Manager, then please click on Cancel", vbOKCancel, "C R I T I C A L !!") = vbOk Then
    Open form
Else
    Do Nothing
End If

Is this not the case of Pandora's box? Why let them get to this point if they are not the information manager.

David
 

PearlGI

Registered User.
Local time
Today, 15:20
Joined
Aug 30, 2001
Messages
125
You need a assign the MsgBox response to a variable and test that. At the moment your line [If vbOKCancel = vbCancel] is just using two different verbs which will always result in a False.

Try the following changes.
Code:
[B]bytAns=[/B]MsgBox[B]([/B]"If you are NOT the Information Manager, then please click on Cancel", vbOKCancel, "C R I T I C A L !!"[B])[/B]
If [B]bytAns [/B]= vbCancel Then DoCmd.Close

You obviously trust your users to be honest and click cancel. :eek:
 

Users who are viewing this thread

Top Bottom