简体   繁体   中英

VBA MS Access Getting the start date in a database

I have a MS Access database and inside it I import tables from an external source every month. What I want to do is get the earliest date in the database since it is out of order. I am creating forms and so far this is what I have:

'Get start and end date
Dim DBGeo As DAO.Database
Dim rstStartDate As DAO.Recordset

Set DBGeo = CurrentDb

varStartDate = "SELECT [time] FROM [" & cboTableName & "] ORDER BY [time] ASC LIMIT 1;"
MsgBox (varStartDate)
Set rstStartDate = DBGeo.OpenRecordset(varStartDate, dbOpenSnapshot)

The field name is called time and I know that is a keyword but I dont want to change it or else I have to change it in all the tables. CboTableName has the name of the table I am using.

Im not great at this stuff so I am sure it is something simple. Thank you

SELECT TOP 1 Table1.Time FROM Table1 ORDER BY Table1.Time;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM