Message box & close worksheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Code bolow doesn't close the worksheet when 'no' is chosen rather than yes.
Any ideas?
Private Sub CommandButton1_Click()

MsgBox("Do you wish to order another item?", _
vbYesNo)

If response = vbYes Then
If vbYes Then
TextBox3.SetFocus
Else
ThisWorkbook.Close True
End If
End If

End Sub
 
Jock,

Try this :-

Private Sub CommandButton1_Click()
response = MsgBox("Do you wish to order another item?", vbYesNo)
If response = vbYes Then
MsgBox ("YES")
'TextBox3.SetFocus
Else
ThisWorkbook.Close savechanges:=True
End If
End Sub

Mike
 
Hi Jock
The code does not work since your are using a variable which has no value
attached.
You may consider amending:

Private Sub CommandButton1_Click()

response = MsgBox("Do you wish to order another item?", _
vbYesNo)

If response = vbYes Then
TextBox3.SetFocus
Else
ThisWorkbook.Close True
End If
End If
End Sub

HTH
Cordially
Pascal
 
try this:


Private Sub CommandButton1_Click()

Dim response

response = MsgBox("Do you wish to order another item?", vbYesNo)

If response = vbYes Then

TextBox3.SetFocus
exit sub
Else

ThisWorkbook.Close True

End If


End Sub
 
hi Jock

You could do like this

Private Sub CommandButton1_Click()

Response = MsgBox("Do you wish to order another item?", vbYesNo)

If Response = vbYes Then
TextBox3.SetFocus
Else
ThisWorkbook.Close
End If

End Sub


hope it helps

S
 
Jock,

Private Sub CommandButton1_Click()
Dim Response as long

Response = MsgBox("Do you wish to order another item?", vbYesNo)

If response = vbYes Then
TextBox3.SetFocus
Else
ThisWorkbook.Close True
End If

End Sub

Also, check the Help for "Option Explicit".

NickHK
 
Many thanks to Mike, Papou, Nick, Snake and Incedental. Job done
Snake, "I heard you were dead" Much better now, I see.lol
 
| Snake, "I heard you were dead" Much better now, I see.lol

the rumours about my death were obviously false :D
 

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

Back
Top