Order of records that DLookup uses to return first value (Access VBA) -


Hunters for a long time but for the first time posters apologize for any social impurity here.

I am trying to use DLookup for a record in the table using VBA. I am after a specific record which is the date of a closest date (a user specified date) which is something Completes other criteria also. There is a possibility of having some records with dates from the same criteria, and I am only interested in that which is the chronological form of the fastest sdate

A simple example of the following is the code I am using to obtain and obtain it. I use baseststring because there are so many similar DLookup expressions, so it saves typing and clarifies the code a bit (at least) to me. DoCmd.OpenTable ("Result") DoCmd.SetOrderBy "[Survey_Date] Desc" DoCmd.Close acTable, ("Result") for Baseline Testing Dlookup basetestString = "[device_ID] = '"& Amp; Equidated & amp; "'And [baseline?] = True_and format ([all_date]," "ddmmyyyy" ") format (" _ & amp; sdate & amp;;, "" ddmmyyyy "") "' Set variable [ Form]! [Results] [text_A] = Nz (DLookup ("[Input]", "[Results]", _ basetestString))

I believe (probably undoubtedly) that DLookup Firstly, the record assumes that it matches the specified criteria. Therefore, the table was designed to be sorted in chronological order, thinking that it would be the order that the DLookup would be recorded through the records. However, every time I run the code, I get returned the least possible date that matches the parameters which are instead of the nearest of the scade. Some games around , I believe that DLookup uses the primary key as the basis of cycling through record (first date is first recorded, and therefore an initial key used by autonumber which is less than the later dates Land).

This is happening leads to my questions ...

1) I am right in believing that when I'm back incorrect records?

2) What's the way I'm trying to use DLookup? Can I choose which field is used to record for DLookup? It is not possible to assign date fields as primary keys because the date can not always be unique.

3) Is there any other way that I am trying to do here?

Thank you very much

To rely on the record order in a relational database Is unsafe for. You need to get the date, you can use DMax, but I think that in this case a record set will be fast.

  Due RA Rexenset Dim DB Database DIS as DAU String Set DB = Current DB SSQL = "Selection Input" _ & amp; "From results" _ & amp; "WHERE Result. [Baseline?] = Truth" _ & amp; "And results.equipment_id = '' & amp; Equidated & amp;" '"_ _" and "result." Survey_date = (SELECT "_" and "maximum (result.date)" _ and " WHERE results. [Baseline?] = True "_" and the result. '& Amp; ";" "and" "&" and results.survey_date & lt; # "& format (sdate," yyyy / Mm / dd ") and" # "" set rs = db.OpenRecordset (ssql)                 

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -