Yes No VB

G

Guest

I have a combo box which selects the name. The user is warned whether or not
he wants to change the name. If he selects yes then he can move on. If he
selects no then the name doesn't change.

I need help on finishing the last part of the code, if the user selects no
then the name doesn't change.

Dim intResponse As Integer

'display a Yes/No message box to the user
intResponse = MsgBox("Are you sure you want to change Preparer's Name?",
vbYesNo, "Change?")

'determine how the user responded and act accordingly
If intResponse = vbYes Then
MsgBox "Change confirmed."
ElseIf intResponse = vbNo Then
MsgBox "Change cancelled."

End If

End Sub
 
W

Wayne Morgan

While the ElseIf will work, since there are only 2 options, if it isn't Yes
then its No. So, just an Else would work. The next thing you need to do is
Undo the selection change. This will work if the combo box is a bound
control.

If intResponse = vbYes Then
MsgBox "Change confirmed."
Else
Me.cboComboName.Undo
MsgBox "Change cancelled."
End If
 
G

Guest

Thanks,
but I still don't know whats wrong, the combo box is a bound control

here is the code

Dim intResponse As Integer

'display a Yes/No message box to the user
intResponse = MsgBox("Are you sure you want to change Preparer's Name?",
vbYesNo, "Change?")

'determine how the user responded and act accordingly
If intResponse = vbYes Then
MsgBox "Change confirmed."
Else
Me.Combo73.Undo
MsgBox "Change cancelled."
End If

End Sub
 
S

SusanV

Hi Lee,

If you are using an integer variable type I think you need to use the value
6 for yes... That's what I do anyways
 
G

George Nicholson

As written, the code seems to be fine.

So, where is the code located? In the BeforeUpdate event of the Combo?
(that's probably where you want it...)

HTH,
 
W

Wayne Morgan

Where is the code located? You say it doesn't work, what does it or doesn't
it do. Please be specific.
 
J

John Vinson

I have a combo box which selects the name. The user is warned whether or not
he wants to change the name. If he selects yes then he can move on. If he
selects no then the name doesn't change.

I need help on finishing the last part of the code, if the user selects no
then the name doesn't change.

Dim intResponse As Integer

'display a Yes/No message box to the user
intResponse = MsgBox("Are you sure you want to change Preparer's Name?",
vbYesNo, "Change?")

'determine how the user responded and act accordingly
If intResponse = vbYes Then
MsgBox "Change confirmed."
ElseIf intResponse = vbNo Then
MsgBox "Change cancelled."

End If

End Sub

If you're doing this in the Combo Box's BeforeUpdate event (which I'd
recommend), you can simply set the automatically-provided Cancel
argument to True. If you wish to blank out the user's selection you
can also use the Undo method on the combo box. It might be a bit
better (because more flexible) to use a SELECT CASE rather than an If:

Private Sub cboMyCombo_BeforeUpdate(Cancel as Integer)
Dim intResponse As Integer

'display a Yes/No message box to the user
intResponse = _
MsgBox("Are you sure you want to change Preparer's Name?", _
vbYesNo, "Change?")

'determine how the user responded and act accordingly

Select Case intResponse
Case vbYes
MsgBox "Change confirmed.", vbOKOnly
Case vbNo
Cancel = True
MsgBox "Change cancelled.", vbOKOnly
Me!MyCombo.Undo
Case Else
Msgbox "OOPS! This shouldn't happen"
End Select
End Sub

John W. Vinson[MVP]
 

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