Open Form based on date

MARKYB0Y

Registered User.
Local time
Today, 22:36
Joined
Jun 28, 2008
Messages
18
Hi All,

I have a form that lists scoresheets, dates are predefined on these scoresheets, what I would like is for when this form is called the row displayed is not row 1 but whatever date is nearest to todays date but not in the future

how can I do this?
 
Try basing it on a query:

SELECT Blah
FROM TableName
WHERE DateField = (SELECT MAX(DateField) FROM TableName WHERE DateField <= Date())
 
Hi PBaldy,

I have tried that but it does not seem to work

the table is called Scores and the date field is called date

I tried this

Code:
SELECT *
FROM Scores
WHERE Date = (SELECT MAX(Date) FROM Scores WHERE Date <= Date());

and the query ran correctly

but when I change the record source of the form it still opens on the first record?

any ideas?
 
Problem: Date is a reserved word in Access and you have a field named Date. Rename it!
 
I agree with George, but to test bracket the field name:

[Date]
 
Bracketing the Date has made the query run, but it isnt going to the correct row, it is only listing the one row, from there I am unable to select previous records.
 
Oh, I misunderstood. You want all records available, just start out at that record? One way would be a using a bookmark, either from the calling form, or perhaps in the load event of the form. Use a recordset or DMax to get the relevant date, then use that in the bookmark code to go to that record.
 
Hi Pbaldy,

apologies fro not making myself clearer, but yes I want all records available, I simply want the first records visible to be the most recent record.

I am not familiar with a bookmark code, can you elaborate please?

thanks
 
I have been trying using the query in the OnOpen and OnClick events but to no avail. So I want all 30 rows of the table to be available but when the form opens I need it to open to the record with the most recent date.

thanks for all your help
 
Sorry, I was busy over the holidays. Did you sort this out, or still need the bookmark code?
 
Hi Pbaldy,

I have not been able to find anything based on bookmark code, so anythin gyou could provide would be greatfully received

thanks
 
If you can post a sample db, I can do it to your form, which would make it most relevant to you.
 
Okay, then you're stuck with what I have laying around. :p

Here's a sample of what I meant.
 

Attachments

Users who are viewing this thread

Back
Top Bottom