SteveL13
asked on
DLast not working correctly
I'm using this code to get the last record in a table:
=DLast("[StatinsMed]","Tre atment","[ MemberID] = " & [Forms]![frmMemberMaster]! [txtMember ID])
But it isn't working. It's actually giving me the middle of 3 record values.
????
=DLast("[StatinsMed]","Tre
But it isn't working. It's actually giving me the middle of 3 record values.
????
ASKER
I guess I've been living in a cave. I would think that DLast would give me the last records value. DMax and DMin do not work either.
asuming that the memberID is a string:
DLast("[StatinsMed]","Trea tment","[M emberID] = '" & [Forms]![frmMemberMaster]! [txtMember ID]) & "'"
as string needs to be wrapped in single quotes
DLast("[StatinsMed]","Trea
as string needs to be wrapped in single quotes
withou the qoutes, the domain function filter is not valid and acts like DLast("[StatinsMed]","Trea tment","")
sorry i misstyped my first comment. it should read like:
DLast("[StatinsMed]","Trea tment","[M emberID] = '" & [Forms]![frmMemberMaster]! [txtMember ID] & "'")
sorry i misstyped my first comment. it should read like:
DLast("[StatinsMed]","Trea
> I would think that DLast would give me the last records value.
Then you will have to define the criteria for "last record".
It could be the newest value of a timestamp field.
/gustav
You can use the DFirst and DLast functions to return a random record from a particular field in a table or query when you simply need any value from that field. Use the DFirst and DLast functions in a macro, module, query expression, or calculated control on a form or report.> DMax and DMin do not work either.
Then you will have to define the criteria for "last record".
It could be the newest value of a timestamp field.
/gustav
The help entry - http://office.microsoft.com/en-001/access-help/dfirst-dlast-functions-HA001228823.aspx explains what you get with DFirst() and DLast() and it isn't what you think it should be. I'm not even sure what the point of having these two function is since they get lots of folks in trouble and don't seem to deliver useful results.
Keep in mind that in English, First and Last refer to ordinal position in a set. In a relational database, tables/queries are unordered sets so First and Last have no fixed meaning since from one query to the next, First and Last could be different. That's why the help entry says you get a random result.
As Gus suggested, tell us what you are really after and we'll see how to make Min/Max solve the problem.
Keep in mind that in English, First and Last refer to ordinal position in a set. In a relational database, tables/queries are unordered sets so First and Last have no fixed meaning since from one query to the next, First and Last could be different. That's why the help entry says you get a random result.
As Gus suggested, tell us what you are really after and we'll see how to make Min/Max solve the problem.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You should use DMax or DMin for the highest or lowest value.
/gustav