Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Select MAX date statement. 1

Status
Not open for further replies.

DajTwo

Technical User
Jul 17, 2008
157
US
Access 2003.

I am trying to get the Max Date value in a table to the variable "LstUpd" but I always get a type mismatch at the SELECT line.

Can someone point me to my error? Thanks!!!

Dim db As Database
Dim rsUpdate As Recordset
Dim LstUpd As Date

Set db = CurrentDb
Set rsUpdate = db.OpenRecordset("tbl_update")

LstUpd = "SELECT Max(tbl_update.last_update) AS As_Of FROM [tbl_update]"

MsgBox "The database was last updated on #" & LstUpd & "#. Do want to update the database?", vbYesNo, "Database Update"

 
Code:
Dim db As Database
Dim rsUpdate As Recordset
Dim LstUpd As Date

Set db = CurrentDb
Set rsUpdate = db.OpenRecordset("SELECT Max(tbl_update.last_update) AS As_Of FROM [tbl_update]"

LstUpd = rsUpdate!As_Of

MsgBox "The database was last updated on #" & LstUpd & "#.  Do want to update the database?", vbYesNo, "Database Update"
 
So far but yet soo close.

I have learned something again.

A zillion minus one left.

Many thanks pwise. Happy holidays.

 
Why not simply this ?
rsUpdate = DMax("last_update", "tbl_update")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV.

Thanks for the alternate solution.. I will also give it a try.

For a newbie like me, differnet solutions to a problem are great. !!

 
Sorry for the typo, I meant:
LstUpd = DMax("last_update", "tbl_update")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top