can you please help me in my code

MsgBox "Are you sure you want to Logout?", vbYesNo, "Confirmation"

If vbYes Then
    Unload Me
    frmAuthentication.Show
    End If

how can i have 2 choices example i want vb no and just stay with my form help me..

Can you reword "how can i have 2 choices example i want vb no and just stay with my form help me.."

It is not clear what you need.

Thanks

ok sir for example

If vbYes Then
    Unload Me
    frmAuthentication.Show
ElseIf vbno then
    Unload Me
(EXAMPLE I JUST WANT TO STAY WITH THE FORM)

end if 

Like that sir but its not correct thanks :D

the msg box is this

Edited 1 Year Ago by Christian_4: jejeje

Attachments jaja.jpg 14.83 KB

but if i click yes it will log out and even i pick no it still log out :(

No need for an Else statement since that does nothing.

Dim reply As Integer = MsgBox("Are you sure you want to Logout?", vbYesNo, "Confirmation")

If reply = vbYes Then
    Unload Me
    frmAuthentication.Show
End If
Private Sub cmdLogout_Click()
Dim reply As Integer = MsgBox("Are you sure you want to Logout?", vbYesNo, "Confirmation")
If reply = vbYes Then
Unload Me
frmAuthentication.Show
End If
End Sub

Here sir! ty

Looks oks to me. Can you zip and send me the whole solution?

Message me for my email if you want to send it.

In vb6 you can't use declaration= dadada but you need to seperate these.

Private Sub cmdLogout_Click()
Dim reply As String
reply = MsgBox("Are you sure you want to Logout?", vbYesNo, "Confirmation")
If reply = vbYes Then
Unload Form1
frmAuthentication.Show
End Sub

This makes me always question is it vb6 or vb.net?

Dim responce As Integer 
responce = MsgBox("Are you sure you want to Logout?", vbYesNo, "Confirmation")
If reply = vbYes Then
    Unload Me
    frmAuthentication.Show
else
    exit sub
End If

Edited 1 Year Ago by Reverend Jim: Already answered, and your code won't work.

You need to use the same variable for the return value as well as the test. You used responce to save the result but your test uses reply. Another possibility would be

If MsgBox("Are you sure you want to Logout?", vbYesNo, "Confirmation") = vbYes Then
    Unload Me
    frmAuthentication.Show
else
    exit sub
End If

Edited 1 Year Ago by Reverend Jim

Comments
That is the version I use.

thanks reverend jim my mistake thanks for pointing out i use response in what ever code i write for myself so in the description they were using reply and i used description in a mistake

Comments
Setting Option Explicit at the beginning of the file can help catch this kind of thing.
Yeah. I've done that.

Another way of handling this is with a Select block:

Select Case MsgBox("Are you sure you want to Logout?", vbYesNo, "Confirmation")
Case vbYes
    frmAuthenticaion.Show
    Unload Me
Case vbNo
    Exit Sub
End Select

Using a Select block gives you more flexibility for when you are using an option that gives more than two answers, like vbYesNoCancel or vbAbortRetyIgnore.

If there is nothing after the Select or If-Then block, then you drop the Exit Sub if you want.

This article has been dead for over six months. Start a new discussion instead.