Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    irfanparbatani is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    17

    Vlookup from the base table

    Hi Friends



    I am writing here in regards to a scenario which I have recently come across and not being able to resolve it, would need you guys expertise on this.

    Route Type ByRoad/Air Jan Feb MAR APR DEC
    123....100......road.......22..22...22...22...22


    I want to write a query in which i will be executing a price column in which I will combine Route, Type and ByROAD/AIR columns and get the price according to the month.

    Please help. I am using Dlookup but the result is varying

    Thanks and Regards
    Last edited by June7; 07-23-2014 at 05:41 PM.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Your table is structured wrong. Queries search top/down, not left to right.

    Structure should be:
    route, type, ByRoadAir, month, price
    123 , 100 road, Jan, 22

    This way a single query will return anything you ask.
    Your current stucture, you must execute a query for each month column. (try not to use: Dlookup. Queries are faster)
    but it would be
    Dlookup("[route]","tbl","[jan]=22" )
    then
    Dlookup("[route]","tbl","[feb]=22" )
    etc...

  3. #3
    irfanparbatani is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    17
    Quote Originally Posted by ranman256 View Post
    Your table is structured wrong. Queries search top/down, not left to right.

    Structure should be:
    route, type, ByRoadAir, month, price
    123 , 100 road, Jan, 22

    This way a single query will return anything you ask.
    Your current stucture, you must execute a query for each month column. (try not to use: Dlookup. Queries are faster)
    but it would be
    Dlookup("[route]","tbl","[jan]=22" )
    then
    Dlookup("[route]","tbl","[feb]=22" )
    etc...

    ----------------------------------------------------------------------------------------

    I want to find total price and I am having table in the similar way you mentioned from Top to bottom. And what do I use to find with various criteria like route+type+byroad and find price from month column.

    Regards

  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,624
    Where would the month parameter come from?

    The table structure is not normalized but can be dealt with.

    Maybe like:

    SELECT ID, DateOrder, DLookUp(Format([DateOrder], "mmm"), "PricesTable", "Route='" & [Route] & "' AND Type='" & [Type] & "' AND [ByRoad/Air]='" & [ByRoad/Air] & "'") AS Price FROM OrdersTable;


    BTW, should avoid spaces and special characters/punctuation (underscore is exception) in naming convention. Better would be ByRoadAir or Road_Air.
    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
    irfanparbatani is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    17
    Quote Originally Posted by June7 View Post
    Where would the month parameter come from?

    The table structure is not normalized but can be dealt with.

    Maybe like:

    SELECT ID, DateOrder, DLookUp(Format([DateOrder], "mmm"), "PricesTable", "Route='" & [Route] & "' AND Type='" & [Type] & "' AND [ByRoad/Air]='" & [ByRoad/Air] & "'") AS Price FROM OrdersTable;


    BTW, should avoid spaces and special characters/punctuation (underscore is exception) in naming convention. Better would be ByRoadAir or Road_Air.
    ================================================== =====

    Hi Mate

    Thanks for the reply

    This is how my table would look like:
    Route Type Road_Air JAN FEB MAR APR MAY JUN JUL AUG
    125 Liquid Road 12 12 12 12 12 12 12 12
    126 Metal Air 13 13 13 13 13 13 13 13
    125 Waste Road 14 14 14 14 14 14 14 14
    124 Plastics Air 15 15 15 15 15 15 15 15
    115 Glass Air 16 16 16 16 16 16 16 16
    130 Paper Air 17 17 17 17 17 17 17 17
    If I select Route and Type and Road_AIR and if the current month is July Then 12 dollars for particular route should be displayed.

    Thanks for your help
    Route Type Road_Air JAN FEB MAR APR MAY JUN JUL AUG
    125 Liquid Road 12 12 12 12 12 12 12 12
    126 Metal Air 13 13 13 13 13 13 13 13
    125 Waste Road 14 14 14 14 14 14 14 14
    124 Plastics Air 15 15 15 15 15 15 15 15
    115 Glass Air 16 16 16 16 16 16 16 16
    130 Paper Air 17 17 17 17 17 17 17 17

  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,624
    Okay, so where are you 'selecting' Route and Type and Road_Air?

    Did you try the suggestion offered?
    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
    irfanparbatani is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    17
    Quote Originally Posted by June7 View Post
    Okay, so where are you 'selecting' Route and Type and Road_Air?

    Did you try the suggestion offered?
    -----------------------------------------------------

    Yes I tried it and there are only few values displaying from Price table and I have one table where data will be saved and other table as prices one to compare it according to the above mentioned query. Tried your query and few values are missing when that particular route and type is selected.

  8. #8
    irfanparbatani is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    17
    Quote Originally Posted by June7 View Post
    Okay, so where are you 'selecting' Route and Type and Road_Air?

    Did you try the suggestion offered?

    --------------------------------------------------------------------------------------------------------------
    I am using the below query to get the output from the table

    Price: DLookUp(Format([SvcDate],"mmm"),"[BNE_Subbie_Prices_Table]","[RouteNo]='" & [Subbie_Clean_Data].[RouteNo] & "'" & " [Type]='" & [Subbie_Clean_Data].[Type] & "'" & " [BNE_Subbie_Prices_Table].[Road_Air]= '" & "Road" Or "Air" & "'")


    I am not getting appropriate output.

  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,624
    Need the AND operator in the WHERE CONDITION argument. Look at my example again.

    The Road_Air criteria syntax is not correct. Why are you using literal text and not referencing field same as for RouteNo and Type?

    Why is the WHERE argument referencing two tables?

    That is not the entire query statement.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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
    irfanparbatani is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    17
    Quote Originally Posted by June7 View Post
    Need the AND operator in the WHERE CONDITION argument. Look at my example again.

    The Road_Air criteria syntax is not correct. Why are you using literal text and not referencing field same as for RouteNo and Type?

    Why is the WHERE argument referencing two tables?

    That is not the entire query statement.

    If you want to provide db for analysis, follow instructions at bottom of my post.


    ----------------------------------------
    Sorry My bad for the incorrect query.

    Correct Query for which the result is not showing up is as follows:

    Price: DLookUp(Format([SvcDate],"mmm"),"[BNE_Subbie_Prices_Table]","[RouteNo]='" & [Subbie_Clean_Data].[RouteNo] & "'" & " [Type]='" & [Subbie_Clean_Data].[Type] & "'" & " [Road_Air]= '" & "[Subbie_Clean_Data].[Road_Air]" & "'")

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    That is not a query, it is just one expression used in query.

    Do not put [Subbie_Clean_Data].[Road_Air] within quote marks.

    Still not using the AND operator. PLEASE review my example in post 4.
    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
    irfanparbatani is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    17
    Quote Originally Posted by June7 View Post
    That is not a query, it is just one expression used in query.

    Do not put [Subbie_Clean_Data].[Road_Air] within quote marks.

    Still not using the AND operator. PLEASE review my example in post 4.


    ----------------------------------------------------------------------------

    Still no luck My new query is as follows:
    Price: DLookUp(Format([SvcDate],"mmm"),"[BNE_Subbie_Prices_Table]","[RouteNo]='" & [Subbie_Clean_Data].[RouteNo] & "'" AND [Type]='" & [Subbie_Clean_Data].[Type] & "'" AND [Road_Air]= '" & [Subbie_Clean_Data].[Road_Air] & "'")

    Still no prices is coming up

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Extra quote marks in front of each AND. Try:

    Price: DLookUp(Format([SvcDate],"mmm"), "[BNE_Subbie_Prices_Table]", "[RouteNo]='" & [Subbie_Clean_Data].[RouteNo] & "' AND [Type]='" & [Subbie_Clean_Data].[Type] & "' AND [Road_Air]= '" & [Subbie_Clean_Data].[Road_Air] & "'")
    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.

  14. #14
    irfanparbatani is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    17
    I tried the same still no luck

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    The syntax is correct and works for me.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. VLookup
    By chethan1333 in forum Access
    Replies: 1
    Last Post: 02-23-2013, 10:14 AM
  2. Replies: 2
    Last Post: 10-09-2012, 03:20 PM
  3. Vlookup in Access with SQL
    By jogunjobi in forum Queries
    Replies: 1
    Last Post: 01-30-2012, 07:25 PM
  4. converting base 32 to base 10?
    By brandonze in forum Access
    Replies: 13
    Last Post: 08-01-2011, 04:11 PM
  5. Replies: 2
    Last Post: 11-29-2010, 11:16 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