• Change row source for a combo box (2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Change row source for a combo box (2000)

    Author
    Topic
    #387252

    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?

    Viewing 1 reply thread
    Author
    Replies
    • #675197

      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

    • #675256

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

      • #675298

        Hmmm… sorry 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 smile

        • #675330

          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

    Viewing 1 reply thread
    Reply To: Change row source for a combo box (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: