Consulting

Results 1 to 4 of 4

Thread: Userform ComboBox loaded from Access

  1. #1

    Userform ComboBox loaded from Access

    This is my first post and I hope I'm posting in the correct place...

    I am loading several userform combo boxes from an access file. Right now I have to use individual 'lookup' tables to load each combo box. I would really like to use one 'Lookup' table with different columns but can't seem to get it to work. It seems that if the columns don't have an equal amount of rows filled out the combo boxes come up blank. Any assistance would be great!!!

    '///Load Model cbo
    rst.Open "SELECT DISTINCT [Model] FROM Models ORDER BY [Model];", cnn, adOpenStatic
    rst.MoveFirst
    With Me.cboModel
    .Clear
    Do
    .AddItem rst![Model]
    rst.MoveNext
    Loop Until rst.EOF
    rst.Close
    End With

  2. #2
    '///Load Model cbo
    'The following line corrected the issue:
    rst.Open "Select * from [Lookup] WHERE Department ORDER BY [Department]", cnn, adOpenStatic, adLockOptimistic
    'Old code: rst.Open "SELECT DISTINCT [Model] FROM Models ORDER BY [Model];", cnn, adOpenStatic

    rst.MoveFirst
    With Me.cboModel
    .Clear
    Do
    .AddItem rst![Model]
    rst.MoveNext
    Loop Until rst.EOF
    rst.Close
    End With

  3. #3
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    FYI, you don't need a loop:
    rst.Open "Select [Model] from [Lookup] WHERE Department ORDER BY [Department]", cnn, adOpenStatic, adLockOptimistic
    Me.cboModel.Column = rst.GetRows
    should suffice, and is also more efficient than returning a load of fields you don't need.
    Be as you wish to seem

  4. #4
    Thank you Aflatoon! This should help speed up the loading when connecting through VPN.

Tags for this Thread

Posting Permissions

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