Results 1 to 12 of 12
  1. #1
    twisted is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    9

    lookup\Autofill

    Hello all,

    Is it possible to look up 2 field to auto fill another field?


    Field 1 is "Exposure" this autofill with "Probability" is user input.
    I need to lookup Exposure and Probability and autofill a score in to "Risk Rating". This to stop incorrect data being inputted.
    I have a table with all the results combination in it.
    Would it be possible to use a Dlookup to look at Exposure and Probability to give me the score

    I tried a Combox with autofill. But the power to be would like it done without user input.

    Thanks
    Andrew

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You mean something like:

    DLookup("Score", "tablename", "Exposure='" & Me.textboxExposure & "' AND Probability='" & Me.textboxProbability & "'")
    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
    twisted is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    9
    Thanks June7
    Can I put this in to Control Source?
    or
    Can I put it under "event procedure" on charge?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The expression can be used in ControlSource, or in query, or in code.
    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.

  5. #5
    twisted is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    9
    Quote Originally Posted by June7 View Post
    The expression can be used in ControlSource, or in query, or in code.
    I ended up using ControlSource on my form. but it is returning #name?. I have also noticed [] around my code.
    This is what my code looks like, including the [] that i get after entering.
    =DLookUp("RiskRating","tblRisk","ExcavationRating= '" & [Me].[ExcavationRating] & "'AND Probability='" & [Me].[TextboxProbability] & "")

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Sorry, the Me. prefix is intended only for VBA code. It is an alias for the full form name. Drop that if using in ControlSource. In a query would have to use the actual form name.

    Don't forget a space in front of the AND after the apostrophe.
    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.

  7. #7
    twisted is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    9
    Thanks again,

    I did try it in VBA first time around. i ended up with a compile error.
    Still the same problem
    =DLookUp("RiskRating","tblRisk","ExcavationRating= '" & [TextboxExcavationRating] & "' AND Probability='" & [TextboxProbability] & "")

  8. #8
    twisted is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    9
    I can post the database if you think it will help at all.
    Its not pretty tho

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You can provide db. Follow instructions at bottom of my post.

    If you use in VBA code, need to set a variable or field or control to the value returned by the DLookup, like:

    Me![Risk Rating] = DLookup(...)
    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.

  10. #10
    twisted is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    9
    MWRA.zip

    Welcome to comment on anything in the database. As i am still new at this.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The DLookup isn't using the actual field names from tblRisk nor the actual field or textbox names from the form. Don't use the dummy names from the example I provided, use your real names.

    I don't see fields in tblRisk that correspond to Probability and ExcavationRating.

    Domain aggregate functions (DLookup, DSum, DCount, etc) follow this syntax:

    FunctionNameHere("fieldname with desired data to return", "tablename to search", "criteria expression")

    Example of criteria expression:

    "fieldname in table = parameter"

    Parameter can be a concatenated variable. Reference to form field/textbox is a variable.

    "fieldname in table = " & textbox or field from form
    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.

  12. #12
    twisted is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    9
    Quote Originally Posted by June7 View Post
    The DLookup isn't using the actual field names from tblRisk nor the actual textbox names from the form. Don't use the dummy names from the example I provided, use your real names.

    I don't see fields in tblRisk that correspond to Probability and ExcavationRating.
    Sorry. That was a mistake. Did not mean to provide miss leading information.

    tblRisk is as follow. "Probability" is "Risk" and "ExcavationRating" is "RiskLetter". "RiskRating" is "Number". So I need to look at the "Risk" & "RiskLetter" to come up with a "Number" which is my RiskRating.

    Again thank you June7 and sorry for the trouble
    Last edited by twisted; 01-02-2013 at 04:26 AM.

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

Similar Threads

  1. Autofill / lookup issue
    By bertollini in forum Access
    Replies: 9
    Last Post: 02-24-2012, 06:08 AM
  2. Autofill ?
    By Daryl2106 in forum Access
    Replies: 14
    Last Post: 10-28-2011, 10:09 AM
  3. Zipcode Lookup Autofill
    By jgalloway in forum Access
    Replies: 25
    Last Post: 09-20-2011, 06:54 PM
  4. Autofill
    By evosheas in forum Access
    Replies: 4
    Last Post: 09-20-2011, 02:29 PM
  5. Autofill
    By kdcooper88 in forum Access
    Replies: 1
    Last Post: 09-18-2010, 05:52 AM

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