Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Posts
    4

    Red face Unanswered: Auto Poplulate a field

    Hello. I have two tables "Employees" with two fields "Name" and "Badge Number". The second table "Checkout" has multiple fields and the first two are "EmployeeName" and "EmployeeNumber". I made the first one "EmployeeName" a lookup field from the table "Employee" and The second field "EmployeeNumber" as a number "not a lookup".

    I created a form based on the "Checkout" table which atutomatically created a combox for the EmployeeName field since it is a lookup field.

    I created a textbox field on the form to diplay the badge number and then store its content in the Badgenumber field of checkout table. My question is this. I want the textbox that displays the badge number on the form gets popluated automatically once I choose the employee from the combo box above it. I tried using DLOOKUP function but i did not work. can someone help me with this. Also, since my form is based on the checkout table, will the badgenumber field on the form send the data to the cooresponding field in the table "checkout" automatically. Sorry..i know this is a basic question but i just started working with access.

  2. #2
    Join Date
    Nov 2002
    Posts
    150

    Re: Auto Poplulate a field

    The combobox should have RowSource something like SELECT BADGE_NUMBER, NAME FROM EMPLOYEES. The ControlSource should be the name of the badge number textbox on your Checkout form.

  3. #3
    Join Date
    Jan 2003
    Posts
    46
    qah2000

    No apologies needed for basic questions. They are the most important.

    First an off topic note. Try to use some naming conventions for your tables and other objects (i.e.: tblCheckout instead of Checkout). It helps in figuring out what wort of object is being referred to.

    Now back on topic: Open the form in design view, right click on the combo box and you will get a Properties dialogue box. Click on the Data tab and then go to Row Source. Open up the row source (you will end up with a query in design view). Make sure that your query contains the Badge NUmber field from the Employee table. And to prevent confusion, make sure it is the 2nd field in the query.

    Close the query, go back to the Properties box and click on the Event's tab. There will be an event for After Update (this isn't the only event that might work for your purpose). Click on the little button (with the down pointer) near the right side of the After Update line and add [Event Procedure]. Then click on the adjacent button (with three little dots) and open up the VBA code screen. What you see should look like:

    Private Sub YourComboBoxName_AfterUpdate()

    End Sub

    Insert the following code line:

    Me.txtBadgeNumber = Me.cboYourComboBoxName.column(1)


    Make sure you get the correct names for your textbox and combobox. What this will do is pass the value of the 2nd column in the combo box to the text box.

    But one more thing: back to the combo box's properties. Click on the Format tab, go down to the Column Count property and make sure that it is at least 2.

    Cheers, Bill

Posting Permissions

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