Simple OK/Cancel box

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?
 
J

John Smith

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top