Solved

Obtaining Latest Date from Table

Posted on 2013-05-25
5
388 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now