Simple OK/Cancel box

  • Thread starter Thread starter Aaron Howe
  • Start date Start date
A

Aaron Howe

I'm trying to get up a very simple message box assigned to
a click action on a button, which will run a msgbox
function giving a warning with an OK and a Cancel button.

Private Sub Command19_Click()

MsgBox "Are you sure you have entered the details
correctly?" & Chr(13) _
& "Once you click OK, you cannot edit this section
again without restarting", vbOKCancel + vbExclamation

If vbOK Then
Me.cboCltName.Locked = True
Me.cboAgName.Locked = True
Me.txtInvNum.Locked = True
Me.txtPONum.Locked = True
Me.txtWkEnd.Locked = True

ElseIf vbCancel Then
End If
End Sub
It works, but it works regardless of whether OK or Cancel
is clicked: either way the fields are locked. I never
seem to have this problem with Excel, Access seems to
treat these things differently...! Can anyone point me in
the right direction?
 
You are using the wrong form of MsgBox, you need to use it as a function:

Private Sub Command19_Click()
if MsgBox("Are you sure you have entered the details correctly?" & vbCrLf _
& "Once you click OK, you cannot edit this section again without
restarting", _
vbOKCancel + vbExclamation) = vbOK Then
Me.cboCltName.Locked = True
Me.cboAgName.Locked = True
Me.txtInvNum.Locked = True
Me.txtPONum.Locked = True
Me.txtWkEnd.Locked = True
End If
End Sub
 
Back
Top