Solved

dmax for recordset

Posted on 2013-05-17
12
280 Views
Last Modified: 2013-05-20
hey guys,

could yall help me see what's wrong with this code?

Dim dateDataStorage As Date
Dim dateRetentionWorkHours As Date

Dim dbWBRRetention As DAO.Database
Set dbWBRRetention = OpenDatabase(CurrentProject.Path & "\WBR BE - Retention.mdb")

Dim rsRetentiontblWorkHours As Recordset
Set rsRetentiontblWorkHours = dbWBRRetention.OpenRecordset("tblWorkHours")


dateDataStorage = Int(DMax("[Planned Start]", "tblDataStorage"))
'dateRetentionWorkHours = Int(DMax("[DateOfWork]", "tblWorkHours"))
dateRetentionWorkHours = Int(DMax("[DateOfWork]", "rsRetentiontblWorkHours"))

Open in new window


problem is on line 13. line 12 works ok though.

the error i get is thiserror message
0
Comment
Question by:developingprogrammer
  • 5
  • 4
  • 3
12 Comments
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39174058
It's very simple. Here:

DMax("[DateOfWork]", "rsRetentiontblWorkHours"))

rsRetentiontblWorkHours must be a table name or query name, not a recordset.

/gustav
0
 

Author Comment

by:developingprogrammer
ID: 39174063
whao thanks for the quick reply gustav! as it turns out rsRetentiontblWorkHours is a recordset ha, so how do i find the max for the recordset? thanks in advance!! = ))
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39174179
--- >>> Set rsRetentiontblWorkHours = dbWBRRetention.OpenRecordset("tblWorkHours")

Since rsRetentiontblWorkHours is nothing more than the records from tblWorkHours (no additional criteria), you dont need to call out the recordset name in your DMax.  Just use this:

dateRetentionWorkHours = Int(DMax("[DateOfWork]", "tblWorkHours"))

And use the recordset as needed elsewhere in your code.

It looked like you already tried that though.  what was the problem with it?

Also, why are you converting to Int?  Why not just this?

dateRetentionWorkHours = DMax("[DateOfWork]", "tblWorkHours")
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 250 total points
ID: 39174195
Oh... your referring to a different database.  Try ordering your recordset by DateOfWork descending so that the first record in the recordset is the most recent like this:


Set rsRetentiontblWorkHours = dbWBRRetention.OpenRecordset("SELECT * FROM tblWorkHours ORDER BY DateOfWork DESC")
If rsRetentiontblWorkHours.Recordcount = 0 then 
       msgbox "No records"
       Exit Sub  '(or function)
End If
dateRetentionWorkHours = rsRetentiontblWorkHours("DateOfWork")
' the rest of your code follows

Open in new window


(There are other ways to do this too...)
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 250 total points
ID: 39174245
Yes, I would do samewise, but you only need the top record:

Set rsRetentiontblWorkHours = dbWBRRetention.OpenRecordset("SELECT TOP 1 * FROM tblWorkHours ORDER BY DateOfWork DESC")

/gustav
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39174268
Definitely go with the TOP 1 as Gustav is suggesting if this is your only purpose for the recordset.  My own post (using the whole recordset) is assuming that you have additional code that you haven't posted,  using the full recordset in other ways.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:developingprogrammer
ID: 39176779
Whao you guys, you guys are fantastic. What would I do without y'all? You are the wind beneath my wings. Haha = ) but yes it's really really reassuring and like the feeling of having a mobile phone vs not having a mobile phone having you guys = )

Will try this later on in the day. Thanks guys!! = ))
0
 

Author Closing Comment

by:developingprogrammer
ID: 39179889
thanks guys!!!! = ))
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39179917
Glad we could help out :-)
0
 

Author Comment

by:developingprogrammer
ID: 39179921
Yup, and a lot mbizup!! = ))
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39180260
You are welcome!

/gustav
0
 

Author Comment

by:developingprogrammer
ID: 39180541
Thanks gustav!! = ))
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

744 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

10 Experts available now in Live!

Get 1:1 Help Now