Consulting

Results 1 to 4 of 4

Thread: Solved: Show Userform problem

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Solved: Show Userform problem

    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"

    [VBA] 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 [/VBA]
    Peace of mind is found in some of the strangest places.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Because you declare ans as a string, and compare it to vbYes, a Long.

    Declare ans as a Long.

  3. #3
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    thanks
    Peace of mind is found in some of the strangest places.

  4. #4
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    If you just want to evaluate the answer to a messagebox, don't worry about creating a variable for this:

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

    [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •