If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Find Second Most Recent Date

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-25-11, 12:22
daryllyrad daryllyrad is offline
Registered User
 
Join Date: Jul 2011
Posts: 5
Find Second Most Recent Date

I'm pretty new to VBA, i'm trying to fill out a form using information from the most recent date and the next most recent date of a table. I need the name of the table to be a variable, which seems to be causing problems. Right now i have

Dim StudentName As String

MostRecentDate = DMax("TestDate", StudentName)

NextDate = DMax("TestDate", StudentName, "TestDate <> MostRecentDate")


The mostrecentdate works, the second works if the name of the domain is not a variable. There will never be duplicate dates, i'm not worried about it skipping entries with the same date.

Right now, each student has a table with test date rows, and test type columns. I need the dates so i can scan through the table with

With rstStudent
Do Until .EOF
For Each fldTestDate In .Fields
If fldTestDate.Name = "TestDate" Then
If fldTestDate.Value = MostRecentDate Then

'fill form with info from this row

Exit Sub
End If
End If
Next
.MoveNext
Loop
End With

Any ideas?
Reply With Quote
  #2 (permalink)  
Old 07-25-11, 19:37
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
It should be:
Code:
NextDate = DMax("TestDate", StudentName, "TestDate <> #" & MostRecentDate & "#")
The way your code is written, MostRecentDate is litteral as it is included in quotes.
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old 07-26-11, 17:00
daryllyrad daryllyrad is offline
Registered User
 
Join Date: Jul 2011
Posts: 5
thank you so much, i hoped it was something easy like that
Reply With Quote
  #4 (permalink)  
Old 07-27-11, 02:50
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
You're welcome!
__________________
Have a nice day!
Reply With Quote
Reply

Tags
date, dmax, form, recent, vba

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On