Results 1 to 9 of 9
  1. #1
    dylcon is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Ann Arbor
    Posts
    130

    Checking Empty comboboxes


    Hello, I am trying to see if a combobox is empty, disable that combobox and force user to enter information into an additional form. As of now, I have this:

    Code:
    Private Sub PartNumbercbo_AfterUpdate()    If Me.PONumbercbo = "" Then
            Me.WarningLabel.Visible = True
            'Me.PONumbercbo.Enabled = False
        Else
        Me.PONumbercbo.Enabled = True
        Me.PONumbercbo.Requery
        
        'Update PONumbercbo
        strSourceOne = "SELECT PP.PartPOID, PO.PONumber " & _
                        "FROM tblPartPO AS PP, tblPOInfo AS PO " & _
                        "WHERE PartID = " & Me.PartNumbercbo _
                        & " AND PP.POInfoID = PO.POInfoID " _
                        & " ORDER BY PO.PONumber"
        Debug.Print strSourceOne
     
        Me.PONumbercbo.RowSource = strSourceOne
        Me.PONumbercbo = vbNullString
        End If
    
    
                    
    End Sub
    but it is not working. The PONumbercbo is staying disabled (which is the default setting for opening the form.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Try


    If Len(Me.PONumbercbo & vbNullString) = 0 Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    First guess that you are confusing Access by using PP and PO as these are table names.
    Just a first glance guess.

    Dale

  4. #4
    dylcon is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Ann Arbor
    Posts
    130
    Dale, that has been working the whole time before so I don't think it is that.
    PBaldy, I have tried that as well, and it still does not work...

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Are you testing the right combo? What you have doesn't do this: "see if a combobox is empty, disable that combobox"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    That's a good question. This code will turn the PONumber combo box on or off depending on the updated value of the PartNumber combo box. Note that the requery statement belongs *after* you set the SQL.
    Code:
    Private Sub PartNumbercbo_AfterUpdate()    
    Dim strSourceOne as String
    
    If Len(Me.PartNumbercbo & vbNullString) = 0 Then
       Me.WarningLabel.Visible = True
       Me.PONumbercbo.Enabled = False
    Else
       Me.WarningLabel.Visible = False
       Me.PONumbercbo.Enabled = True
        
       'Update PONumbercbo
       strSourceOne = "SELECT PP.PartPOID, PO.PONumber " & _
                       "FROM tblPartPO AS PP, tblPOInfo AS PO " & _
                       "WHERE PP.PartID = " & Me.PartNumbercbo _
                       & " AND PP.POInfoID = PO.POInfoID " _
                       & " ORDER BY PO.PONumber"
       'Debug.Print strSourceOne
     
       Me.PONumbercbo.RowSource = strSourceOne
      'Me.PONumbercbo = vbNullString
    End If
                    
    End Sub
    I specified PP.PartID just for practice's sake. Best to specify every field in a complex query, so you know what you'll get.
    Last edited by Dal Jeanis; 06-17-2013 at 02:03 PM. Reason: delete unneeded requery and dim str

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    The Requery is not required after setting a row source.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    That makes sense. Moved the code when I should have deleted it. Fixed now.

    dylcon - in English, what is supposed to happen after the user selects a part number?

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In addition to what Paul said, you have not declared the variable "strSourceOne":

    Dim strSourceOne as String


    Also, you should have these two lines at the beginning of every code page (Module):

    Option Compare Database
    Option Explicit '<<- very important

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

Similar Threads

  1. Replies: 2
    Last Post: 04-23-2012, 10:13 PM
  2. Replies: 4
    Last Post: 11-20-2011, 01:08 PM
  3. Cascade of 3 or more ComboBoxes
    By tomullus in forum Forms
    Replies: 4
    Last Post: 10-08-2011, 06:22 PM
  4. Comboboxes go where?
    By PaulCW in forum Database Design
    Replies: 12
    Last Post: 10-04-2011, 02:34 AM
  5. Code for two comboBoxes
    By t_dot in forum Forms
    Replies: 3
    Last Post: 08-24-2010, 10:20 AM

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