Go To Now()

G

Guest

Hello.
I have created an Access Database to track my tasks. In the design I
imported all the dates from now through 2030 in a field called "TaskDate".

Currently when I open the task form it takes me to the first record then I
have to scroll through the records to the current date. I need it to go to
the current date upon opening the form.

Currently I am trying to get a "Go To Record" macro...
Object Type: Form
Object Name: frm_Taskform
Record: Go To
Offset: =Date() (The offset field can take any type of expression)

This is not working. How do I change it to get it to work?

Your help is greatly appreciated.

Iram/mcp
 
D

Douglas J. Steele

Offset is intended to be an integer that indicates the record number of the
target record.

Access stores dates as the number of days relative to 30 Dec, 1899. That
means that today (18 Mar, 2007) is 39159, so that specifying Date as the
offset is telling Access to move to the 39159th record in the recordset. I
suspect you don't have that many records...

If your recordset is sorted in ascending date order, you want to subtract
the value of the first date in the recordset from today's date in order to
get the desired record number.
 
G

Guest

How would I write that in the "Offset"?

Would this work if say tomorrow I opened the db, would it go to tomorrow's
data automatically? I plan on puting this macro on the "On Open" field Event
of the form so that whenever I open the db it goes to the current date.
 
G

Guest

Would it be easier to do this in vba or macro? If so what would be the sintax?
Thanks.
 
D

Douglas J. Steele

Personally, I never use macros, so I'm obviously biased towards VBA. <g>

Karl's suggestion of using FindRecord might be appropriate.

Assuming you do have one record for every day since Feb 9, 2007, you should
be able to calculate the appropriate value for Offset as

DateDiff("d", #02/09/2007#, Date())
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top