473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Select / Dlookup

Dear Bytes Users

I have created a database for fuel consumption for various vehicles. By entering the date, plantno, mileage_reading and liter. I managed to get the previous mileage_reading via a select statement in query:
- created a query from a table fuelbook and made an alias fuelbook1
- created a new field

Prevmeter: (Select max(meter) from fuelbook Where meter < fuelbook1.[meter] and plantno = fuelbook1.[plantno])

Till there is works perfect and I can retrieve the previous data for the meter reading

Now I am trying to retrieve the previous liter which is depending on previous record, with the same plantno.

I tried it with Dlookup were I can get the previous record but not for the specific plantno, it give only the liter previous ID (as I used ID-1)

I tried also

Prevliter: (Select (liter) from fuelbook Where liter < fuelbook1.[liter] and plantno = fuelbook1.[plantno])

But this gives no result

Anybody who can get me in the right direction
Aug 11 '12 #1
4 2732
zmbd
5,501 Expert Mod 4TB
@Rene

Welcome to the bytes forum!

I think that there may be only a few people that really understand what you're asking... and I'm lost too...
However it's very late/early and I haven't had my nap yet since yesterday so please forgive me if I seem a tad tuttle-and-mule with your question.

Would you please review your question and provide more detail as to what it is you're having issues with?

However, help us to help you - you just might want to review the following threads before re-posting your question:
Posting Guidelines
How to ask good questions
FAQ

Before you get too much farther into your project may I respectfully offer a few links that might help you with your current and future projects:

I’ve found that all too often the textbooks really do a very poor presentation of the actual steps behind setting up a database from scratch. However, I have found a really good step by step tutorial for basic design here (and a good review for those that have done this a few times too IMHO - was for me :-) ): A Tutorial for Access

Although the afore mentioned may sound a tad late for your current project, this tutorial may yet give you some insight to any issues you may run into with your project in the near term and should help you with any future projects.

Of particular note is >> tables <<page within the tutorial - notice the information that is given, the table name, the field name, the field type, key or index, etc... AND the format used to present that data. When you post back, this is the type of information we'll need to help you along in your project. You don't need a fancy grid table to do this... just a line by line layout.

One of the hardest concepts for most people to understand is that of "normalization." I found this link to have a really good really good explanation of the concept for those just starting out and I found it to be a good review when I read thru it: Database Normalization and Table Structures.

Looking forward to helping you with your project...

-z
Aug 11 '12 #2
Many thanks for your quick reply and assistance

OK I have been programming with access for a good while and try to create more to my job specific databases and features.

I just read the links you posted which are clear to me but not any contribution to a solution

Let me show a small part of my table to clarify

Tablename: Fuelbook

ID Date plantno meter Prevmeter mileage liter Prevliter
1 09.05.12 TO 94 91968 64
2 09.05.12 TO 85 97365 52
3 12.05.12 TO 94 92589 91968 621 67 ??64?? (to be extracted by code)
4 12.05.12 TO 85 98200 97365 835 63 ??52?? (to be extracted by code)

For me to compute the fuel consumption for example Plantno TO 94,

I calculate the mileage (meter-prevmeter) and need to divide that figure (621) through the liters previously filled "prevliter" (64) to get ltr/km

Basicly I want to Dlookup or select a previous record (liter) for that specific plantno

DLookup examples are given on the internet but do not relate to filtered records but just a field and an ID
Expr1: DLookUp("[MyField]","MyTable","[ID]=" & [ID]-1)
The above gives me the liter of the previous ID rather than the previous plantno TO 94


Hope things are a bit clearer explained now.

Regards

Rene
Aug 11 '12 #3
twinnyfo
3,653 Expert Mod 2GB
Rene,

I hope this will help. I can't write the query for you, but you may have to use two queries to satisfy your question.

First, create a query whose sole purpose is to identify the record ID of the record you want. Use an aggregate query, and in stead of the group by, use the Max of the last fill up meter reading, limited by all those record that met the PlantNo criteria of the latest fillup. You will also want to exclude the current record.

Once you have that Record ID, use that ID to gather whatever data you need from the table from that record. You would join the table to that query in the second query and the data from just that record should be the only data displayed.

Again, I hope this helps, bu tthese are the steps that I would go through. Some others may have some better ideas. Try some things and if you hit any snags, we will be glad to assist!
Aug 11 '12 #4
zmbd
5,501 Expert Mod 4TB
Rene
Thank you for reading thru the links I posted.
They were not intended to provide a solution... in as much as the question you asked was not clear.
Instead the links I posted were intended to help you help us by way of providing a guideline for you to post your question.
As you can see, Twinnyfo was able to provide some guidence from your second post.
One thing that would help with how you posted the example data would have to used a comma or semi-colon between the field names and the data.
-z
Aug 11 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: KLAU | last post by:
I have a field that retrieves information from an expression in a query. I have used a DLookup function to get the calculated field from the query. However, the relationship is 1-to-many so one...
5
by: Kalvin Schroder | last post by:
I am fairly new to Access, and am trying to put together an invoice form. The main form in called InvoiceDetailFm. Source is the table InvoiceDetail and has invoice number, saleman, and CustID as...
3
by: DFS | last post by:
FYI, Using DLookup("ResultsField","Pass-thru query") consumes 2 SEQUENCE numbers each time it's called. Anyone know why?
4
by: MLH | last post by:
I have tried using DLookUp in this manner... If DLookUp("","tblClients","='2021234567'") Then MsgBox "Found it!" End If I am wondering if that is a misuse of the DLookUp command? Type...
21
by: Thelma Lubkin | last post by:
I would like my DLookup criteria to say this: Trim(fieldX) = strVar: myVar = _ DLookup("someField", "someTable", "Trim(fieldX) = '" & strVar & '") I don't believe that this will work, and I...
8
by: MLH | last post by:
The following SQL returns PRECISELY what I want: SELECT TOP 1 tblCorrespondence.CorrespID, tblOutboundTypes.OTypDescription, tblCorrespondence.OutDate, tblCorrespondence.VehicleJobID,...
0
by: musman | last post by:
hey all, I have tried to use the select statement instead DLookUp function as i have sql server at my backend and access as my front end. But neither DLookUp function is working nor select state...
3
by: Constantine AI | last post by:
Hi can anybody help me with this problem? I have a customer order form with a sales order line subform. The subform contains products ordered by customers, each (wooden) product can come in two...
1
by: Constantine AI | last post by:
Hi i am trying to get User input if data does not exist within a DLOOKUP table. I have gotten it to work for one record but not multiple, i have tried to incorporate my code into a loop procedure but...
3
by: lee weaver | last post by:
I have an odd situtation where a section of code is resetting the status of either multi line If statments which then gives me the error " end if without block if" or something very similure, or ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.