Results 1 to 5 of 5
  1. #1
    Jims Chan is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2016
    Location
    Malaysia
    Posts
    10

    access forms dlookup field from table with between criteria

    Hi all,



    keep trying on the dlookup but can't get the results... searching on forums still couldn't solve, hope experts here could help me. thanks in advance

    i have a table call loading table

    ID NoOfYear Loading
    1 6 0.00%
    2 10 15.00%
    3 11 20.00%

    while a form data entry, which have [CurrentDate],[YearOfMake],[MotorAge] and [Loading] where [loading] need to lookup from loading table
    with criteria motor age determine the loading percentage

    Private Sub YearOfMake_AfterUpdate()
    Me.MotorAge.Value = Year([CurrentDate]) - [YearOfMake]
    Me.Loading.Value = DLookup("[loading]", "loading", "[noofyear]>" & Me.MotorAge & " and [noofyear]<=" & Me.MotorAge & "")
    End Sub

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    You have a field in your table with the same name as the table name?
    NoOfYear in your post is left justified which signifies a text field.
    So in your Dlookup I think you'll need quotes to enclose your variables for proper syntax.
    DLookup("[loading]", "loading", "[noofyear]>'" & Me.MotorAge & "' and [noofyear]<='" & Me.MotorAge & "'")

    However, I think you are trying to do arithmetic so you'll need numbers.
    How are the fields/columns defined in your loading table?

  3. #3
    Jims Chan is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2016
    Location
    Malaysia
    Posts
    10
    Quote Originally Posted by orange View Post
    You have a field in your table with the same name as the table name?
    NoOfYear in your post is left justified which signifies a text field.
    So in your Dlookup I think you'll need quotes to enclose your variables for proper syntax.
    DLookup("[loading]", "loading", "[noofyear]>'" & Me.MotorAge & "' and [noofyear]<='" & Me.MotorAge & "'")

    However, I think you are trying to do arithmetic so you'll need numbers.
    How are the fields/columns defined in your loading table?
    hehehe... i still newbie in access so a lot of thing still in learning...
    i had try ur advice and there is a RUN TIME ERROR '3464' (DATA TYPE MISMATCH IN CRITERIA EXPRESSION)
    so what should i do next???

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    How are the fields/columns defined in your loading table?

    I think you are trying to do arithmetic with different data types (text and numeric) and that's why you got the error message.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    I don't think

    a) dlookup is the right function to use
    b) your criteria requires NoofYear to be both less than and greater than or equal to motorage - which is impossible

    Assuming Noofyear is a number (if it was text then the 'order' would 10,11,6) then if you want the loading for a vehicle aged say 8 years to pick up the 10 year value try

    =DMin("[loading]", "tblloading", "[noofyear]>=" & Me.MotorAge)

    and if you wanted it to pick up the 6 year value then you would use

    =DMax("[loading]", "tblloading", "[noofyear]<=" & Me.MotorAge)

    you also need to think about what happens if the motorage is less than 6 or more than 11

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

Similar Threads

  1. Replies: 4
    Last Post: 08-22-2016, 12:01 PM
  2. Replies: 5
    Last Post: 03-11-2016, 01:03 PM
  3. Replies: 2
    Last Post: 07-12-2015, 08:48 AM
  4. Replies: 4
    Last Post: 06-30-2014, 02:53 PM
  5. Replies: 3
    Last Post: 08-22-2012, 03:51 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