need help with code for combo box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tranzit
    New Member
    • May 2007
    • 18

    need help with code for combo box

    hi i have a form with a combo box and two text boxes on it.
    i want it set up so when a selection is made from the combo box the two text boxes will display the corresponding data from the table.

    the table name is: New Plymouth
    the fields included in the table: Destination
    Kilometres One Way
    Kilometres Return

    the name of the combo box : Dest
    the first text box: Kms
    the 2nd text box: Kms1

    the combo box displays the destinations from the table, i want the Kms text box to display the one way kms and i want the Kms1 text box to display the return kms.

    i currently have the following code which works fine with one text box but i am un sure what changes are required to make it work for two text boxes.

    the code is:

    after update in the combo box

    Private Sub Dest_AfterUpdat e()
    Me!Kms = Me!Dest.Column( 1)
    End Sub

    can anyone please help me???????
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Originally posted by tranzit
    hi i have a form with a combo box and two text boxes on it.
    i want it set up so when a selection is made from the combo box the two text boxes will display the corresponding data from the table.

    the table name is: New Plymouth
    the fields included in the table: Destination
    Kilometres One Way
    Kilometres Return

    the name of the combo box : Dest
    the first text box: Kms
    the 2nd text box: Kms1

    the combo box displays the destinations from the table, i want the Kms text box to display the one way kms and i want the Kms1 text box to display the return kms.

    i currently have the following code which works fine with one text box but i am un sure what changes are required to make it work for two text boxes.

    the code is:

    after update in the combo box

    Private Sub Dest_AfterUpdat e()
    Me!Kms = Me!Dest.Column( 1)
    End Sub

    can anyone please help me???????
    [Code=vb]
    Private Sub Dest_AfterUpdat e()
    Me!Kms = Me!Dest.Column( 1)
    Me!Kms1 = Me!Dest.Column( 2)
    End Sub
    [/Code]

    Comment

    • tranzit
      New Member
      • May 2007
      • 18

      #3
      thanks for the help but i already tryed that and it didn't work i can't work out why???

      Comment

      • tranzit
        New Member
        • May 2007
        • 18

        #4
        the statement i have in the combo box row source is as follows:
        SELECT * FROM [New Plymouth] ORDER BY [New Plymouth].Destination;

        is there something worng with this????

        it works fine with the first text box but nothing appears in the second text box

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          Originally posted by tranzit
          the statement i have in the combo box row source is as follows:
          SELECT * FROM [New Plymouth] ORDER BY [New Plymouth].Destination;

          is there something worng with this????

          it works fine with the first text box but nothing appears in the second text box
          Interesting... it should work perfectly fine. The one time something like this happened to me was because I had overlapping names. Check all field names in the recordsource, function names in the modules, variable names, etc. and see if you've given more than one thing the same name.

          Comment

          • MMcCarthy
            Recognized Expert MVP
            • Aug 2006
            • 14387

            #6
            Originally posted by Rabbit
            Interesting... it should work perfectly fine. The one time something like this happened to me was because I had overlapping names. Check all field names in the recordsource, function names in the modules, variable names, etc. and see if you've given more than one thing the same name.
            Check the Column Count property under the format tab. It should be set to at least 2 if you want to use both the first and second column

            Comment

            • tranzit
              New Member
              • May 2007
              • 18

              #7
              thanks for the help it was the column count that needed changing...
              THANKS EVERYONE :)

              Comment

              • MMcCarthy
                Recognized Expert MVP
                • Aug 2006
                • 14387

                #8
                Originally posted by tranzit
                thanks for the help it was the column count that needed changing...
                THANKS EVERYONE :)
                You're welcome.

                Glad you got it sorted.

                Mary

                Comment

                Working...