Solved

Obtaining Latest Date from Table

Posted on 2013-05-25
5
414 Views
Last Modified: 2013-05-25
I am trying to get the newest date from a table and have it return the record as quickly as possible and feed that date to a textbox.

There are over 200,000 records so I need something that works fast.

My rendition does not work at all. It returns a syntax error of 3075 Syntax Error in Expression.

Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database
Dim strDTE As String
Dim recDTE As DAO.Recordset


Set db = CurrentDb()

strDTE = "SELECT Max(sl_date As MxDTE) FROM tblSlip"

Set recDTE = db.OpenRecordset(strDTE, dbOpenDynaset)

With recDTE
    If .EOF = False Then
        .Move First
        Me.txtEnd = !MxDTE
    End If
    .Close
End With

Set recDTE = Nothing

db.Close
Set db = Nothing
End Sub

Open in new window


Any help appreciated.

Thanks

PBLack
0
Comment
Question by:PBLack
  • 2
  • 2
5 Comments
 

Author Comment

by:PBLack
ID: 39196631
I found it here in my bracketing...a brain fart on my part!

strDTE = "SELECT Max(sl_date) As MxDTE FROM tblSlip"
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 400 total points
ID: 39196634
Try this:
= DMax("[sl_date]","tblSlip")

No need to use a recordset.
0
 
LVL 5

Assisted Solution

by:DOSLover
DOSLover earned 100 total points
ID: 39196663
There is a simple syntax error. The 'Max' function should be only on the date.
Please change
             strDTE = "SELECT Max(sl_date As MxDTE) FROM tblSlip"
To
             strDTE = "SELECT Max(sl_date) As MxDTE FROM tblSlip"
And try again.
0
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 400 total points
ID: 39196672
Here you go:
Private Sub Form_Open(Cancel As Integer)
     Me.txtEnd = DMax("[sl_date]","tblSlip")
End Sub

Open in new window

0
 

Author Closing Comment

by:PBLack
ID: 39196687
Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question