Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2004
    Posts
    82

    Question Unanswered: Combo1 --> Combo2/listbox

    If i had a combo with a load of place names in it can i write a code saying for example:

    If combo1 = "PLACE" then
    combo2 has in it Hotel1, Hotel2

    In combo it needs to be selected(highlighted)

    Would it be easier to use a listbox

    Thanks for help AGAIN!?!?

  2. #2
    Join Date
    Nov 2004
    Posts
    108
    you have to disable combo2 while combo1 has no value and populate and enable combo2 when a value is selected on combo1.

    the best way is to populate combo boxes from tables not hardcoding the content of the comboboxes
    to err is human ; to really mess things up requires a computer

  3. #3
    Join Date
    May 2004
    Location
    Ohio
    Posts
    61
    I recently had similar problems. Tuenty is right though. What kind of backend are you using? What I've done in my instance, is use a set up stored procedures. Set those to strings and then call them up in the VB application. Works like a charm.

  4. #4
    Join Date
    Aug 2004
    Posts
    82
    So i should put all the combos on top of each other and say it combo1 is set to the value of x combo 2 is visable ect

  5. #5
    Join Date
    Nov 2004
    Posts
    108

    Post example

    take this as an example:

    In my Business we have groups and each group have one or more locations

    I have a text box where the user enter the group (this could be combo1)
    When the text box loses focus I validate the group and fill the combo box for locations (this could be your combo2)

    Code:
    Public Sub txtGroup_LostFocus()
        Dim ctlData As New controlData
        If txtGroup.Text <> "" Then
            If imgPlan(1).Visible Then
                txtGroup = Format(Trim(txtGroup), "00000")
            ElseIf imgPlan(2).Visible Then
                If Len(Trim(txtGroup)) < 5 Then
                    MsgBox "El grupo que usted entró no es válido."
                    Exit Sub
                End If
            End If
            ctlData.fillLocations txtGroup.Text, 0
            cboLocation.Enabled = True
    .
    .
    .
    End Sub
    in the class controlData I have a procedure called fillLocations that receives the value of the group the user typed as a parameter


    Code:
    Public Sub fillLocations(group As String, ctlCode As Integer)
        Dim cn As New ADODB.Connection
        Dim strSQL As New sqlCommand
        Dim rs As New ADODB.Recordset
        cn.ConnectionString = cnStr
        cn.Open
        Set rs = cn.Execute(strSQL.retrieveLocations(group))
        If Not rs.EOF Then
            frmAddChange.cboLocation.Clear
            Do Until rs.EOF
                frmAddChange.cboLocation.AddItem rs.Fields("location")
                rs.MoveNext
            Loop
            rs.Close
        End If
        Set strSQL = Nothing
        Set rs = Nothing
        Set cn = Nothing
    End Sub
    using store procedures is what experts recommend it is more efficient and it is more secure
    Last edited by tuenty; 12-07-04 at 11:20.
    to err is human ; to really mess things up requires a computer

Posting Permissions

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