Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2003
    Posts
    280

    Unanswered: A combo box with two column fields...

    How do you set a combo box to populate with two column fields? Having one field hidden as a datafield and the other fields as an display field for user to choose which information they want. Are is there another way to do it?

    I was hoping Visual Basic combo box would be similar to Access. After two days of researching about it and testing it, I have no luck with it. I need y'all help, please. My mind will go insane if I don't figure out how it works...

  2. #2
    Join Date
    Nov 2004
    Posts
    3

    DataCombo

    Maybe DataCombo control may help check help files!

  3. #3
    Join Date
    Nov 2004
    Posts
    30
    suppose your recordset looks like this

    Select EmployeeID,EmpName from Employees

    And i assume your problem is to hide EmployeeID field while displaying EmpName.

    do while rsEmployee.eof
    combo1.additem rsEmployee!EmpName
    combo1.itemdata(combo1.newindex) = rsEmployee!EmployeeID
    rsEmployee.movenext
    Loop


    and u can retrieve it back by
    combo1.itemdata(combo1.listindex)
    Last edited by sudheesh_k_s; 11-27-04 at 11:12.

  4. #4
    Join Date
    Apr 2003
    Posts
    280
    I'm using the Data combo box now rather than the regular combo box (whatever you called it). I have tried both and it didn't work. I have tried a lot of ways before going on here and asking for help.

    Here is the regular combo box code.

    Dim conndb as New ADODB.Connection
    Dim rsTreat as New ADODB.Recordset

    conndb.connectionString = "driver={SQL Server};server=ServerNew;uid=administrator;pwd=adm inistrator;database=TestDB"
    conndb.Open

    rsTreat.Open "HCPCS_Data", conndb, adOpenKeyset, adLockPessimistic, adCmdTable

    Do While rsTreat.EOF
    cboHCPCS.AddItem rsTreat.Fields("Discipline")
    cboHCPCS.ItemData(cboHCPCS.NewIndex) = rsTreat.Fields("HCPCS_ID")
    rsTreat.MoveNext
    Loop

    End Sub

  5. #5
    Join Date
    Nov 2004
    Posts
    30
    you have not said any thing about the error messages. Just tell me the error messages u are getting or the type of problem you are facing. The aboe code works only with normal combo box. For data combo you have to use it in a different way. You have to put an adodc control on the form. The code is give below

    With Adodc1
    .CursorLocation = adUseClient
    .CursorType = adOpenStatic
    .LockType = adLockReadOnly
    .ConnectionString = m_cnnGlobal.ConnectionString ' my connection str
    .RecordSource = "Select EmpID,EmpName from Employees"
    .Refresh


    With yourdatacombo
    Set .DataSource = Adodc1
    Set .RowSource = Adodc1
    .BoundColumn = "EmpID"
    .ListField = "EmpName"
    .Refresh
    End With

    End With
    here EMPID is hidden and EmpName is visible.
    You can add more columns to the select statement and get the values by filtering the adodc

    on clickevent of the datacombo
    varEmpID = Val(Trim$(cmbdatacombo.BoundText))
    with the above variable just filter the adodc and get the values for other columns too.

    Hope that this helps you.

    If you face any other problem pl write the problem with the error message
    Last edited by sudheesh_k_s; 12-01-04 at 07:07.

  6. #6
    Join Date
    Nov 2004
    Posts
    3

    Please sheck!

    after putting Mr.. sudheesh_k_s code in form everything worked until I make probe exe file and then after passing to another control on form, item in DataCombo always return to first record in table from which it was populated!! Please check!

  7. #7
    Join Date
    Nov 2004
    Posts
    30
    Can you paste the code written on the click event of the combo and if you have written code for any other event of the combo please put them too. And also please let me know the other controls on which the focus goes after exiting the combo

Posting Permissions

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