Results 1 to 5 of 5
  1. #1
    Rickinnocal is offline Novice
    Windows 10 Office 365
    Join Date
    May 2020
    Posts
    2

    Populate a field based on other fields


    On my form I have a text field, txtCharge, which will contain the base price for a job. There is also a combo box where I select the client, and one where I select the port.

    I have a table called tblPricing which has a row for each client and a column for each port. The base price for each client at each port is entered.

    If I select "ABC Shipping" for client and "Los Angeles" for port, I'd like the base price to populate the Charge field.

    How do I go about this, please?

    Thanks,
    Richard

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,970
    When you say field, txtCharge, this is actually textbox name? The field in table is Charge? txtCharge is bound to Charge?

    You can have code do a DLookup() to retrieve price or ID.
    Me!Charge = DLookup("Price", "tblPricing", "ClientID=" & Me.Client & " AND PortID=" & Me.Port)

    The real trick is figuring out what event to put code into. Possibly need to use AfterUpdate event of both comboboxes.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Rickinnocal is offline Novice
    Windows 10 Office 365
    Join Date
    May 2020
    Posts
    2
    Thanks, I'll give it a shot. Probably run it on the GotFocus event of the field itself so that the cursor is there ready to type if I want a different price for some reason.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,545
    I have a table called tblPricing which has a row for each client and a column for each port. The base price for each client at each port is entered.
    Not sure that June's suggestion will work if you do actually have a column in the table for each port and only one row for each customer.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,970
    Ooops, I missed "column for each port". tblPricing is not normalized. Consider this instead:

    Me!Charge = DLookup("[" & Me.Port & "]", "tblPricing", "ClientID=" & Me.Client)

    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 10-04-2017, 05:48 PM
  2. Auto-populate 1 field based on 2 fields
    By Ray Peterson in forum Queries
    Replies: 3
    Last Post: 11-10-2015, 12:42 PM
  3. Replies: 7
    Last Post: 11-28-2012, 01:41 PM
  4. Fields populate based on another field
    By jlclark4 in forum Forms
    Replies: 3
    Last Post: 12-27-2011, 05:21 PM
  5. Populate one field based upon another fields data
    By BigBrownBear in forum Queries
    Replies: 1
    Last Post: 03-23-2010, 04:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums