Results 1 to 7 of 7
  1. #1
    jhrBanker is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2009
    Posts
    68

    Populate one form field based on another

    I have a Form (frmCriteria) with a Combobox (cmbSelWsCd) and a Text Field (txtWsMgr).

    I have a table (WS) with the following fields:
    WsCd
    WsDesc
    WsMgr

    The Combobox has WsCd & WsDesc (WsCd is bound).
    When I select the WsDesc from the Combobox I want to populated the Text field txtWsMgr with the corrosponding table value.

    I've tried: DLookup([WsMgr], "WS","[WsCd]=[Forms].[frmCriteria].[cmbSelWsCd]")

    I've entered the following for txtWsMgr Source: SELECT WS.WsMgr FROM WS WHERE (((WS.WsCd)=[Forms].[frmCriteria].[cmbSelWsCd]));

    Any suggestions?


    Thanks

  2. #2
    AlexHedley's Avatar
    AlexHedley is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    England
    Posts
    180

    Populate one form field based on another

    You have the whole Criteria as a String so it isn't using the cbo as a variable
    Code:
    DLookup([WsMgr], "WS","[WsCd]=[Forms].[frmCriteria].[cmbSelWsCd]")
    Change it to
    Code:
    DLookup([WsMgr], "WS","[WsCd]=" & [Forms].[frmCriteria].[cmbSelWsCd])

    What Data Type is WsCd?

    You might need to wrap the DLOOKUP criteria, combo value, in " ' " and " ' " if it is a String

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You don't really say where you're trying to do this, and the syntax varies a little, depending on that. You do it in the cmbSelWsCd_AfterUpdate event, using

    If WsCd is defined as a Text Field

    Code:
    Me.txtWsMgr = DLookup("[WsMgr]", "WS", "[WsCd]= '" & Me.cmbSelWsCd & "'")
    If WsCd is defined as a Number Field

    Code:
    Me.txtWsMgr = DLookup("[WsMgr]", "WS", "[WsCd]= " & Me.cmbSelWsCd)

    BTW, you cannot use a Select Statement to populate a Textbox; you really have to use DLookup.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    jhrBanker is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2009
    Posts
    68
    Yes, WsCd is a string value.
    I tried: DLookup([WsMgr], "WS","'[WsCd]='" & [Forms].[frmCriteria].[cmbSelWsCd]), but still not working. Getting #Name?

  5. #5
    AlexHedley's Avatar
    AlexHedley is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    England
    Posts
    180

    Populate one form field based on another

    You missed the closing " ' "

    Try Linq's

    Code:
    Me.txtWsMgr = DLookup("[WsMgr]", "WS", "[WsCd]= '" & Me.cmbSelWsCd & "'")

  6. #6
    jhrBanker is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2009
    Posts
    68
    Got it. Thanks so much for the help.

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. populate field in a form based on user???
    By DCV0204 in forum Forms
    Replies: 1
    Last Post: 01-17-2013, 08:16 AM
  2. Fields populate based on another field
    By jlclark4 in forum Forms
    Replies: 3
    Last Post: 12-27-2011, 05:21 PM
  3. Replies: 3
    Last Post: 10-03-2011, 02:33 PM
  4. Replies: 3
    Last Post: 12-06-2010, 06:35 PM
  5. Replies: 3
    Last Post: 10-05-2009, 07:22 AM

Tags for this Thread

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