• Combo Box question (Access 2003)

    Author
    Topic
    #424273

    I have a combo box that has values from a table in it. The fields in the table are Name, Emp#, and Activity. The combo box has the Activity in it. When the database loads, the user enters a login name. I want the value in the combo box to be the persons corresponding activity in the table, but they can change the value in the box if they prefer. Any help is appreciated.
    Nick

    Viewing 0 reply threads
    Author
    Replies
    • #973872

      Is the combo box on the same form where the user enters the login name?

      • #973874

        It is on another form. A login form pops up and the user enters their name and selects ok. Another form loads with the combo box. their name is placed at the top of this form and i want the combo box to have the value of the activity that corresponds with the entered name.

        • #973876

          Put the following code in the On Load event of the form with the combo box:

          Private Sub Form_Load()
          Me.cboActivity = DLookup(“Activity”, “tblSomething”, “[Name] = ” & Chr(34) & Forms!frmLogin!txtName & Chr(34))
          End Sub

          where:
          – cboActivity is the name of the combo box
          – tblSomething is the name of the table
          – frmLogin is the name of the login form.
          – txtName is the name of the text box on the login form where the user enters the login name.

          • #973883

            Here is my code

            Me.cmbActCode = DLookup(“activity”, “tblEmployee”, “Name = ” & Chr(34) & [Forms]![frmlogin]![cmbEmpName].Column(0) & Chr(34))
            The name is coming froma combo box on the frmLogin. The code blows up when i run it. It just shows up a blank form.

            • #973888

              Could you post a stripped down copy of your database? See post 401925 for instructions.

            • #973893

              The database is pretty large. I will try to size it down. Let me try to clarify my problem.

              I have a frmLogin where the user selects their name from a combo box and the selects an OK button.
              A new form comes up where the user can input misc data in textboxes, and one of the input items is a combo box that is the particular users activity performed. This activity is stored in a table with the users name. I want the default value in the combo box to be the activity associated with the selected name on the login screen, However I want the user to be able to select a different value in this activity combo box.

            • #973894

              The problem is clear. I’ll wait for the stripped down copy of the database.

            • #973901

              Here is a versioin of the database.

            • #973905

              Thanks. The easiest solution is to add the activity code to the Row Source combo box on frmLogin (modify the Row Source, increase the Column Count to 5 and add an extra column width of 0). The On Load code for frmMain then becomes

              Private Sub Form_Load()
              Me.cmbActCode = Forms!frmLogin!cmbEmpName.Column(4)
              End Sub

              In the attached version I had to create a table to act as Record Source for frmMain, you had removed it.

            • #973984

              Thanks HansV, that worked perfect.
              Thanks again,
              Nick

    Viewing 0 reply threads
    Reply To: Combo Box question (Access 2003)

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

    Your information: