Jenkins
asked on
vbYesNo MS Access
I'm having trouble with vbYesNo in Access.
I have a vbYesNo msgbox with a long message under a command button.
I am now trying to check whether the user selected Yes or No.
The problem I'm having is that when I click Yes or No when prompted by the message, the vbYesNo message box is being repeated. Here is the code
'Here is the start of the code where I cause a vbYesNo message box to pop up
If .......some criteria....... Then
MsgBox "bla bla bla....................... " & _
"bla bla bla....................... .......... .... " & _
"bla bla bla", vbYesNo
'Next, i am trying to check if YES was selected. This way of checking is causing the
'the vbYesNo message box to be repeated. This is where the problem is.
If MsgBox("MsgBox "bla bla bla....................... " & _
"bla bla bla....................... .......... .... " & _
"bla bla bla", vbYesNo) = vbYes Then
'After clicking YES twice in the vbYesNo message box that pops up twice, I finally come to here. This where I want to come after clicking YES in the vbYesNo messagebox the first time.
MsgBox "testing yes"
Else
MsgBox "testing no"
End If
I have a vbYesNo msgbox with a long message under a command button.
I am now trying to check whether the user selected Yes or No.
The problem I'm having is that when I click Yes or No when prompted by the message, the vbYesNo message box is being repeated. Here is the code
'Here is the start of the code where I cause a vbYesNo message box to pop up
If .......some criteria....... Then
MsgBox "bla bla bla.......................
"bla bla bla.......................
"bla bla bla", vbYesNo
'Next, i am trying to check if YES was selected. This way of checking is causing the
'the vbYesNo message box to be repeated. This is where the problem is.
If MsgBox("MsgBox "bla bla bla.......................
"bla bla bla.......................
"bla bla bla", vbYesNo) = vbYes Then
'After clicking YES twice in the vbYesNo message box that pops up twice, I finally come to here. This where I want to come after clicking YES in the vbYesNo messagebox the first time.
MsgBox "testing yes"
Else
MsgBox "testing no"
End If
Dim lresponse as integer
Lresponse =msgbox(.....)
If lresponse = 1 then
....
End if
Lresponse =msgbox(.....)
If lresponse = 1 then
....
End if
ASKER
As usual I'm confused. I tried to modify it and now it's repeating the vbYesNo messagebox 3 times before finally getting to the vbYes messagebox
This is what I have now:
Private Sub cmdButton_Click()
Dim StrResponse As String
If .......some criteria....... Then
MsgBox "bla bla bla....................... " & _
"bla bla bla....................... .......... .... " & _
"bla bla bla", vbYesNo
StrResponse = MsgBox("MsgBox "bla bla bla....................... " & _
"bla bla bla....................... .......... .... " & _
"bla bla bla", vbYesNo)
If StrResponse = vbYes Then
MsgBox "testing yes"
Else
MsgBox "testing no"
End If
This is what I have now:
Private Sub cmdButton_Click()
Dim StrResponse As String
If .......some criteria....... Then
MsgBox "bla bla bla.......................
"bla bla bla.......................
"bla bla bla", vbYesNo
StrResponse = MsgBox("MsgBox "bla bla bla.......................
"bla bla bla.......................
"bla bla bla", vbYesNo)
If StrResponse = vbYes Then
MsgBox "testing yes"
Else
MsgBox "testing no"
End If
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Like this:
That should work as is. However, as OCDan's comment pointed out, the response from a message box is actually an integer so this would be better style:
Dim StrResponse As String
StrResponse = MsgBox("MsgBox "bla bla bla....................... " & _
"bla bla bla..................................... " & _
"bla bla bla", vbYesNo)
If StrResponse = vbYes Then
MsgBox "testing yes"
Else
MsgBox "testing no"
End If
That should work as is. However, as OCDan's comment pointed out, the response from a message box is actually an integer so this would be better style:
Dim intResponse As integer
intResponse = MsgBox("MsgBox "bla bla bla....................... " & _
"bla bla bla..................................... " & _
"bla bla bla", vbYesNo)
If intResponse = vbYes Then
MsgBox "testing yes"
Else
MsgBox "testing no"
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
StrResponse= msgbox (....
And check the value of the variable instead of repeating the message box.