Results 1 to 7 of 7

Thread: Combo to Combo problem **Resolved**

  1. #1

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479

    Question Combo to Combo problem **Resolved**

    Thanks jdc2000 your solution was perfect.

    Please bear with me!


    I've got 3 combos.
    Combo1 gets a list of experiments from a db.
    When an experiment is selected in combo1, combo2 gets filled with the possible leg numbers of that experiment, combo3 with the possible descriptions.
    A leg matches to a description. Together they are unique.
    So the exact leg - description combination can be got by either
    selecting from combo2 or combo3. With me so far?
    Now, if I select the leg, I want the description to be automatically shown in combo3 and vice versa.
    But, heres the problem, if the description is chosen I want leg to be auto shown.
    This gets me into an infinite loop type thing. (top english!)
    Combo2 tells combo3 what to show but then combo3 tells combo2 what to show so combo2 tells combo3...... etc. etc.

    Any ideas.
    Last edited by GlenW; Jan 17th, 2002 at 08:52 AM.

  2. #2
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489
    Post the code, hard to tell the problem w/o it.

  3. #3

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    OK this code uses BatchNumber and ReplicateNumber instead of leg and description, but the ideas the same.
    As you can see I disable the other combo so things work, but I want the users to be able to switch between selection methods. So how can I make this work and leave the other enabled.

    VB Code:
    1. Private Sub cboRep_Click()
    2.    
    3.     cboBatch.Enabled = False
    4.    
    5.     If (Not (cboRep.Text = "")) Then
    6.         cnnCon.Open dataText
    7.         rsRes.Open "SELECT DISTINCT BatchNumber " & _
    8.                    "FROM tblShadeDetails " & _
    9.                    "WHERE ProjectTitle = " & Chr(34) & _
    10.                                        cboProject.Text & Chr(34) & _
    11.                    " AND ExperimentID = " & Chr(34) & _
    12.                                        cboExperiment.Text & Chr(34) & _
    13.                    " AND LegNumber = " & Val(cboLeg.Text) & _
    14.                    " AND ReplicateNumber = " & Chr(34) & _
    15.                                       cboRep.Text & Chr(34), _
    16.                     cnnCon, _
    17.                     adOpenKeyset, _
    18.                     adLockReadOnly, _
    19.                     adCmdText
    20.                    
    21.         With rsRes
    22.             If (Not (.BOF And .EOF)) Then
    23.                 .MoveFirst
    24.                 While (Not .EOF)
    25.                     cboBatch.Text = .Fields("BatchNumber").Value
    26.                     .MoveNext
    27.                 Wend
    28.             End If
    29.         End With
    30.        
    31.         rsRes.Close
    32.         cnnCon.Close
    33.        
    34.     End If
    35.    
    36.     setWashCycles
    37.    
    38.    
    39. End Sub

  4. #4
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526
    The way to avoid your infinite loop problem is to not simply update the combo box text automatically, but to check what is in it first to see if it is already correct. If the value is already the correct one (meaning that it has already been updated), then do not update the contents. This will prevent re-triggering the event that signals the update. If you could post the event subs, we could show you what needs to be done to them.

  5. #5

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    Excellent idea jdc2000

    VB Code:
    1. If(cboBatch.Text = .Fields("BatchNumber").Value)Then
    2.     Exit Sub
    3. Else
    4.     cboBatch.Text = .Fields("BatchNumber").Value
    5. End If


    This should do it you think?

  6. #6
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489
    cboBatch.Text = .Fields("BatchNumber").Value
    won't this Just overwrite the FirstItem in the list so that
    only the Last Item in your Record Set will be the only
    Item in your ComboBox??

    Maybe
    cboBatch.Aditem(.Fields("BatchNumber").Value)
    Instead??

  7. #7

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    No it only sets the text property.
    The list is unaffected.
    As the list in the other combo is created at the same time as this one, that is exactly what I want.

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