Results 1 to 9 of 9

Thread: Combo Problems

  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am spending so much time on a stupid problem which does not happen with list boxes. I am using two combos. The first has a rowsource:

    MySql3 = "SELECT SPORTS.Directory1 AS Sport FROM SPORTS"
    MySql3 = MySql3 & " ORDER BY SPORTS.Directory1;"
    Me.Combo1.RowSource = MySql3
    Me.Combo1 = Null
    Me.Combo1.Visible = True
    Me.Combo1.SetFocus
    Me.Combo1.Dropdown

    This all works okay/

    On its click event I have this code:

    Private Sub Combo1_Click
    Me.LNAMEB.Caption = Me.Combo1.Column(0)

    MySql2 = "SELECT DISTINCT Table1.Directory1, Table1.Directory2 FROM Table1 WHERE (((Table1.Directory2) <> ""isnull""))"
    MySql2 = MySql2 & " AND (((Table1.Directory1) Like [Forms]![DocsEntry].[Form].[LNAMEB].[Caption] ))"
    MySql2 = MySql2 & " ORDER BY Table1.Directory2;"
    Me.Combo2.RowSource = MySql2
    Me.Combo2 = Null
    End Sub


    That part works okay. Then the onclick of Combo2 I have:

    Private Sub Combo2_Click()
    Me.LNAMEC.Caption = Me.Combo2.Column(1)
    End Sub

    This puts the selection into the label, but the combo closes showing the first item in the combo list highlighted, ie it never closes with the selected item highlighted.

    Both combos are unbound. Can someone tell me how to avoid insanity, thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Has the Allow Edits property of the form been set to No?
    Has the Locked property of the combo box been set to Yes?

  3. #3
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Hans. Allow edits set yo yes, the combo is not locked, and is enabled. Regards

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I think we'd need to see a stripped down and zipped copy of the database.

  5. #5
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Hans, hope the attached works. The form opens with combo1 dropped down for selection after which combo2 can be selected from. Combo2 value goes into the label caption okay but the combo closes with the wrong item selected.

    The selection of Football ITWS produces values in combo2 to select from

    Regards

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Despite the edit, I don't see an attachment...

  7. #7
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Attachment (did no see earlier failed message)
    Attached Files Attached Files

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You've made things *much* more complicated than necessary.

    The cause of your problem was that the (hidden) first column of Combo2 contained the same value in every row, so Access had no way of distinguishing the rows. You don't need this column.

    This is all the remaining code:

    Code:
    Private Sub Combo1_Click()
      Me.LNAMEB.Caption = Me.Combo1
      Me.Combo2.Requery
      Me.Combo2 = Null
      Me.LNAMEC.Caption = ""
    End Sub
    
    Private Sub Combo2_Click()
      Me.LNAMEC.Caption = Me.Combo2
    End Sub
    
    Private Sub Form_Open(Cancel As Integer)
      Me.Combo1.SetFocus
      Me.Combo1.Dropdown
    End Sub
    Attached Files Attached Files

  9. #9
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you so much Hans, I went round that problem for hours not being able to figure it out. Very greatful to you, regards

Posting Permissions

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