Results 1 to 10 of 10
  1. #1
    kcphila is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    7

    very new user, question about DLOOKUP and Access in general

    New user, going from basically data entry with Access to some more complicated, but I'm pretty sure still quite basic, tasks. I've got something I think I need DLOOKUP to do, but i'm not sure.

    What I need to do is to fill a column with the data that corresponds to the value in Wt Code, with the name of the Columns after weight code. So, if Wt Code is "2" the data I'd need would be the data from the 2 column. I thought I could do this with data keys, but I think I need to use DLookup. Is that the correct tool?


    Click image for larger version. 

Name:	access question.png 
Views:	18 
Size:	24.8 KB 
ID:	21298


  2. #2
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    IN Theory, Not tested.

    Code:
    Public Function GetCustPrice(ByVal strCustomer As String)
    On Error GoTo Err_GetCustPrice
        Dim inWtCode As Integer ' declare variable to store WT Code in
        intWtCode = DLookup("[Wt Code]", "[Main Table]","[Cust#]='" & strCustomer & "'") ' Get the WT Code and store in intWTCode
        ' Return the associated field with Wt Code, If there isn't one return 0
        GetCustPrice= Nz(DLookup("[" & intWtCode & "]", "[Main Table]", "[Cust#]='" & strCustomer & "'"), 0)
    Safe_GetCustPrice:
        Exit Function
    Err_GetCustPrice:
        Debug.Assert Err.Number <> 0
        Resume Safe_GetCustPrice
    End Function

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    use a query. the query would link to the price table and update all fields price/wt etc.
    Dlookup is for a form to pull 1 bit of info.
    If youre filling a table, use a query.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Since there are only 6 cost fields, perhaps an expression in query will serve:

    Choose([Wt Code], [1], [2], [3], [4], [5], [6])

    Advise no spaces or special characters/punctuation (underscore is exception) in naming convention.
    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
    kcphila is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    7
    An expression was how I've been trying to do it. So I should use CHOOSE. Thanks!

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    This presumes the table with the 6 cost fields is included in the query, as shown in the image for Query3.
    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
    kcphila is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    7
    Quote Originally Posted by ranman256 View Post
    use a query. the query would link to the price table and update all fields price/wt etc.
    Dlookup is for a form to pull 1 bit of info.
    If youre filling a table, use a query.
    I did that, when I ran the query it came up with a prompt which asked me to "name the parameter". I'm not sure what that's asking me to do, but whatever I name the parameters is is what it returns in the column.

  8. #8
    kcphila is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    7
    Quote Originally Posted by June7 View Post
    This presumes the table with the 6 cost fields is included in the query, as shown in the image for Query3.
    I did that, when I ran the query it came up with a prompt which asked me to "name the parameter". I'm not sure what that's asking me to do, but whatever I name the parameters is is what it returns in the column.
    Attached Thumbnails Attached Thumbnails wrtcodequery.jpg  

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The image showed field names of [1], [2], [3], [4], [5], [6]. How did those fields get created? Use correct field names in the Choose() function.
    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
    kcphila is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    7
    I just realized my error. Sorry! It's working exactly how I need it too. Thanks!

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

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2012, 11:30 AM
  2. General Access Structure Question
    By caw442000 in forum Access
    Replies: 6
    Last Post: 10-13-2011, 06:49 PM
  3. General question about access
    By TEE in forum Access
    Replies: 2
    Last Post: 05-30-2011, 07:50 AM
  4. General access connectivity question..
    By quahtrader in forum Access
    Replies: 10
    Last Post: 02-25-2010, 08:45 AM
  5. General Access Question
    By erose1987 in forum Access
    Replies: 1
    Last Post: 04-01-2009, 12:37 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