Results 1 to 8 of 8

Thread: linking data between dbcombo boxes

  1. #1

    Thread Starter
    Addicted Member DKasler's Avatar
    Join Date
    Jan 2005
    Location
    Brooklyn, NYC
    Posts
    177

    linking data between dbcombo boxes

    I have 3 dbcombo boxes on my form. If the user selects something from box one... I want it to sort box2 and have box2 only display info pertaining to the choice made in box 1, then when they choose something from box2 I want it to sort box3 and have box 3 only display info pertaining to the choice made in box 2


    DBCombo1 Choice -------> DBCombo2 [Choices related to DBCombo1] -------> DBCombo3 [Choices related to DBCombo2].

    I tried to figure it all out on my own but alas, I could not come up with a means of pulling it off.
    -----MY SITES-----
    BayRidgeNights.Com - NYC Nightlife Forums

    Fight Communism - Rate Posts!

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: linking data between dbcombo boxes

    I do something like that, where I use the LostFocus event of the first combobox, which loads the second combo, and as soon as something is clicked in the second combo, a third combo is loaded with items that are particular to the first two combos.

    You could run a query to load the combos. If they are bound, then you would have to change the record.

  3. #3

    Thread Starter
    Addicted Member DKasler's Avatar
    Join Date
    Jan 2005
    Location
    Brooklyn, NYC
    Posts
    177

    Re: linking data between dbcombo boxes

    Well i tried running a query... but I couldnt exactly figure out how to get the data from the query to the dbcombo boxs listfield property... That and the row source property MUST be set at design time, not runtime (as far as I know).

    Here is the query i was trying to use

    VB Code:
    1. Dim sConnect As String
    2.     Dim sSQL As String
    3.     Dim dfwConn As ADODB.Connection
    4.  
    5.     ' set strings
    6.     sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=M:\supplies\supplies.mdb;Persist Security Info=False"
    7.     sSQL = "select ProdID,Items,Type,Supplier from Products"
    8.    
    9.     ' open connection
    10.     Set dfwConn = New ADODB.Connection
    11.     dfwConn.Open sConnect
    12.  
    13.     ' create a recordset using the provided collection
    14.     Set datprimaryRS = New ADODB.Recordset
    15.     datprimaryRS.CursorLocation = adUseClient
    16.     datprimaryRS.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly
    17.  
    18.     DBCombo2.RowSource = datprimaryRS
    -----MY SITES-----
    BayRidgeNights.Com - NYC Nightlife Forums

    Fight Communism - Rate Posts!

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: linking data between dbcombo boxes

    I found this, and it may help you:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub cboStudent_Click(Area As Integer)
    4.  Dim Y As Single
    5.  Dim StrQuery1 As String
    6.  
    7.  txtStudNo.Text = cboStudent.BoundText
    8.  
    9.  StrQuery1 = "select teacher_name & ', ' & teacher_first as t_name,teacher_name,teacher_no from teacher inner join stud_teach on teacher.teacher_no = stud_teach.st_teacher_no where stud_teach.st_student_no = " & Val(cboStudent.BoundText)
    10.  datTeacher.RecordSource = StrQuery1
    11.  datTeacher.Refresh
    12.  
    13. End Sub
    14. Private Sub Form_Load()
    15. Dim file_name As String
    16. Dim strQuery As String
    17.  
    18.     file_name = App.Path
    19.     If Right$(file_name, 1) <> "\" Then file_name = file_name & "\"
    20.     file_name = file_name & "Example.mdb"
    21.  
    22.     datTeacher.DatabaseName = file_name
    23.     datStudent.DatabaseName = file_name
    24.  
    25.  strQuery = " select teacher_name & ', ' & teacher_first as t_name,teacher_name,teacher_no from teacher order by teacher_name"
    26.  datTeacher.RecordSource = strQuery
    27.  datTeacher.Refresh
    28.  
    29. End Sub
    Attached Files Attached Files
    Last edited by dglienna; May 10th, 2005 at 04:05 PM.

  5. #5

    Thread Starter
    Addicted Member DKasler's Avatar
    Join Date
    Jan 2005
    Location
    Brooklyn, NYC
    Posts
    177

    Re: linking data between dbcombo boxes

    yea... I think im going to have to figure something else out, because I have no idea what that code you posted does.
    -----MY SITES-----
    BayRidgeNights.Com - NYC Nightlife Forums

    Fight Communism - Rate Posts!

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: linking data between dbcombo boxes

    Did you try out the code? It works, and shows how to use the DE with a combo box.

  7. #7

    Thread Starter
    Addicted Member DKasler's Avatar
    Join Date
    Jan 2005
    Location
    Brooklyn, NYC
    Posts
    177

    Re: linking data between dbcombo boxes

    whoops. Sorry I didnt see that attachment when I first looked. Thanks DG
    -----MY SITES-----
    BayRidgeNights.Com - NYC Nightlife Forums

    Fight Communism - Rate Posts!

  8. #8
    Lively Member
    Join Date
    May 2004
    Posts
    72

    Question Re: linking data between dbcombo boxes

    Waht about programming this without using bound controls? I heard bound controls are devil, is it true ? can we do this same code without the data control.

    Cybersandokan

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