Results 1 to 3 of 3

Thread: Load second combo box

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    102

    Load second combo box

    This code works for first combo box. How would I populate the second box on the form load? Thanks!

    Private Sub Form_Load()
    Dim lrs As ADODB.Recordset
    Set m_con = New ADODB.Connection
    Call m_con.Open("DRIVER={SQL Server};SERVER=(LOCAL);UID=Cust;PWD=aaa")
    If m_con.State = adStateOpen Then
    Set lrs = New ADODB.Recordset
    Set lrs.ActiveConnection = m_con
    lrs.CursorLocation = adUseClient
    lrs.CursorType = adOpenStatic
    Call lrs.Open("SELECT * FROM Talk..ProgramsOffered")
    Call LoadCombo(cmbProgram, lrs, "ProgramName", "ProgramKeyField")
    If cmbProgram.ListCount > 0 Then
    cmbProgram.ListIndex = 0
    End If
    End If



    Second ComboBox Info:

    Call lrs2.Open("SELECT * FROM Talk.._UserName ORDER BY SortSeq")
    Call LoadCombo(cmbUserName, lrs2, "UserName", "UserNameKey")
    If cmbUserName.ListCount > 0 Then
    cmbProgram.ListIndex = 0
    End If

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Load second combo box

    First of all, when you post code please put it inside VBCode tags - either using the button in the post editor screen, or by putting them in manually, like this: [vbcode] 'code here [/vbcode]

    Also, when some code you have written isn't working, it's best to tell us why it isn't (such as any error messages that are shown).

    Anyhoo, you appear to be missing these lines:
    VB Code:
    1. Set lrs2 = New ADODB.Recordset
    2. Set lrs2.ActiveConnection = m_con
    3. lrs2.CursorLocation = adUseClient
    4. lrs2.CursorType = adOpenStatic

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    102

    Re: Load second combo box

    Thanks, worked like a charm. I'll use the vb quotes next time as well as give the error.

Posting Permissions

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



Click Here to Expand Forum to Full Width