Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Nov 2002
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change row source for a combo box (2000)

    I have a combo box that needs to change its row source depending on the value of another combo box. Example: if cbo1 = "value1" then cbo2 will draw its row source from table1. If cbo1 ="value2" then cbo2 will draw its row source from table2. Can anyone help with this?

  2. #2
    3 Star Lounger
    Join Date
    May 2002
    Location
    Toronto, Ontario, Canada
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change row source for a combo box (2000)

    You need to add the following code to the BeforeUpdate Event for the cbo1... If there are more than 2 values that decide which table is the rowsource then you can use a Select Case structure...

    Forms!form1.cbo2 = "" 'this will clear cbo2
    If cbo1 = "value1" Then
    Forms!form1!cbo2.RowSource = "YourTable"
    Else
    Forms!form1!cbo2.RowSource = "YourOtherTable"
    End If


    Oh... and you'll still have to play with the Bound Column to figure out what field to display in cbo2...
    Hope this makes sense... Let me know if you need more detailed instructions... HTH

  3. #3
    New Lounger
    Join Date
    Nov 2002
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change row source for a combo box (2000)

    What is the proper way to reference a table as a row source?

  4. #4
    3 Star Lounger
    Join Date
    May 2002
    Location
    Toronto, Ontario, Canada
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change row source for a combo box (2000)

    Hmmm... <img src=/S/sorry.gif border=0 alt=sorry width=15 height=15> aaucoin... I'm not sure I understand what you are asking...

    If you want to know the proper syntax to designate a table as the row source its:
    Forms!frmName!cboName.RowSource = "tblName"
    (which means: Assign the table named "tblName" -> to the RowSource property -> of the combo box named "cboName" -> on the form named "form1" -> in the Forms collection... )

    If you want to know how to properly designate that the data to be contained in that combo box will be coming from a Table or Query, rather than a Field List or Value List... then this is the code:
    Forms!frmName!cboName.RowSourceType = "Table/Query"

    Let me know if I'm completely misunderstanding... HTH <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  5. #5
    New Lounger
    Join Date
    Nov 2002
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change row source for a combo box (2000)

    You didn't misunderstand me. I did want to know the proper syntax to designate a table as the row source. I was thinking that there was more to it than just the table name. I thought that I had to list the row in the table as well. The way I finally got it to work was:
    cboName.RowSource = "SELECT tblmodel.Model FROM tblmodel"
    I coppied the select statement from the row source in the properties and put it into the code. It took me a while to figure out that I needed to put quotes around the statement, though.
    Thanks for your help

Posting Permissions

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