• September 23, 2021

PHSARIT

Bring Technology Ideas with you

 How to populate one Column From Table into Combobox using VBA programming in the same Database in Microsoft Access

Developer sometimes can be tricked how to load value from tables in order to be more easier for them to be selected the value from the dropdown list. By going through this scenario, the programmers must create a table in order to load this data into Combobox in order to prevent adding more job in the VBA programming. They can only add data into table and it will be populated into Combobox automatically.

In order to work with this tutorial, it needs to create one table and one form to store the Combobox control.

Create Table Users To Store UserName in the Table

Going to Create Table then select Table Design

    Table Design

    After that create some field names such as Userid, Username, Password, Gender, Role as image below then Save as user_info and after that click on Ok

      user_info Table

      Microsoft Access will promptly ask the question to get Primary Key for id, so you just click on No

        Primary Key defined alert

        Going back to your Table on the left panel, then select on the user_info table to add some data or record into the table

          Add Some record into user_info Table

          Create Form Design to Store Combobox Control

          Within Create Tab, select More Forms then Modal Dialogue then in the control panel in Design Tab, please select Combobox control to drag into Form Design

            Combobox Control in Design Tab

            After dragging into Form Design then select Cancel, please go to property sheet and rename this Combobox as cboUsername

              Design Form for Combobox

              To write VBA programming language, please right click on Form Design then select Build Event after that Code Builder. On the Detail event, please select Form Load

                Panel of VBA coding on Form Load event

                In Form Load, please copy this code below:

                Private Sub Form_Load()
                Me.cboUsername.RowSourceType = "Table/Query"
                Me.cboUsername.RowSource = "select Username from user_info"
                End Sub

                See the result below after you have used the code the above

                  Result in Form View

                  Related post