PDA

View Full Version : Solved: Show Userform problem



austenr
04-24-2006, 09:39 AM
Does anyone know why if you select vbYes in the code below it will not display userform2? This works fine in one module but the same code does not show the userform in the other module. If you select vbYes in the one that does not work, the value in ans = "38"

Sub AskToPrintReport()
Dim ans As String
ans = MsgBox("Do you want to create a report?", vbYesNo) + vbQuestion
If ans = vbYes Then
UserForm2.Show
End If
End Sub

Bob Phillips
04-24-2006, 10:04 AM
Because you declare ans as a string, and compare it to vbYes, a Long.

Declare ans as a Long.

austenr
04-24-2006, 10:15 AM
thanks

geekgirlau
04-26-2006, 12:13 AM
If you just want to evaluate the answer to a messagebox, don't worry about creating a variable for this:


Sub AskToPrintReport()
If vbYes = MsgBox("Do you want to create a report?", _
vbYesNo + vbQuestion) Then
UserForm2.Show
End If
End Sub