Results 1 to 3 of 3
  1. #1
    KrisDdb is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58

    Post MsgBox in VBA Editor not popping up

    I have a form with a combo box and a button, which when clicked, opens a report based on the option selected in the combo box. For this, in the event procedure of the button click, how do I code it so that if no option is selected in the combo box and the button is clicked, it should display a 'message' as a pop up. I know I should use the MsgBox option but I seem to be going wrong with the If loops. I doubt I am positioning the MsgBox command in the wrong place in the code below, as it does not pop up the msg box as I desire. What do I need to do to get over this?

    Heres the code:

    Private Sub btnMarket_Click()

    If Me.Combo0 <> "" And Not IsNull(Me.Combo0) Then
    Dim s As String
    s = "1=1"

    If Me.Combo0 <> "ALL" Then
    s = "Market = '" & Combo0 & "'"

    End If

    DoCmd.OpenReport "repNewIntakeMarket", acViewPreview, , s

    Else

    MsgBox "Please select an option from the list of markets. Select All to view all markets.", vbOKOnly, "Market Required"

    End If



    End Sub

    Appreciate your time and thoughts.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Try:
    Code:
    Private Sub btnMarket_Click()
    Dim s As String
    If IsNull(Me.Combo0) Then
        MsgBox "Please select an option from the list of markets. Select All to view all markets.", vbOKOnly, "Market Required"
    Else
        If Me.Combo0 = "ALL" Then
            s = "1=1"
        Else
            s = "Market = '" & Combo0 & "'"
        End If
        DoCmd.OpenReport "repNewIntakeMarket", acViewPreview, , s
    End If
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    KrisDdb is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58

    Thumbs up That worked!

    Oh! The things I do!! I was equating Me.Combo0 <> "ALL" instead of Me.Combo0 = "ALL". I added a bit more to your code as I had to put in a second combo box based on the value of the first one (newer requirement!). In case someones interested, this is what it looks like now:

    Code:

    Private Sub btnIntakeMarket_Click()

    If Me.Combo0.Value = "Choose Market" Then

    MsgBox "Please select an option from the list of markets. Select All to view all markets.", vbOKOnly, "Market Required"

    Else
    If Me.Combo0 = "ALL" Then
    Dim s As String
    s = "1=1"

    Else

    If Me.Combo0 <> "ALL" Then
    s = "Market = '" & Combo0 & "'"

    If Combo1 <> "ALL" And Combo1 <> "" And Not IsNull(Combo1) Then
    s = s & " AND [type] = '" & Combo1 & "'"
    End If
    End If

    End If
    DoCmd.OpenReport "repNewIntakeMarket", acViewPreview, , s

    End If

    End Sub

    Appreciate the quick and precise reply. Will mark this as solved.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-14-2011, 03:42 PM
  2. VB Editor requires password
    By Desstro in forum Import/Export Data
    Replies: 7
    Last Post: 02-24-2011, 12:04 AM
  3. Replies: 1
    Last Post: 11-23-2010, 09:16 PM
  4. HTML Editor
    By mystifier in forum Forms
    Replies: 3
    Last Post: 11-11-2010, 05:51 AM
  5. Text editor
    By smiles_chicago in forum Forms
    Replies: 0
    Last Post: 10-21-2008, 12:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums