On Open form go to record

I

Iram

I am trying to add something to a Form's Events "On Open".
When I open a Form I need the form to go to todays date or current date.
On the "On Open" field I have tried stuff like =Date=Now()
The name of the date field is Date. I have already appended dates from
1-9-07 to 1-1-2030. Currently when I open the form it goes to the first
record.

I also have tried (see below) on the "On Open" and it still doesn't work.

Private Sub Form_Open(Cancel As Integer)
DoCmd.Maximize
Me![Date].SetFocus
DoCmd.FindRecord Date, acEntire, , , , acCurrent, True

How do I get the form to go straight to todays date?

Your help is greatly appreciated.

Thanks.
Iram/mcp
 
A

Allen Browne

FindFirst in the RecordsetClone of the form.

Example:

Dim rs As DAO.Recordset
DoCmd.OpenForm "Form1"
With Forms("Form1")
Set rs = .RecordsetClone
rs.FindFirst "[Date] = " & Format(Date, "\#mm\/dd\/yyyy\#")
If rs.NoMatch Then
MsgBox "Can't find today"
Else
.Bookmark = rs.Bookmark
End If
End With

Note that Date is a reserved name in JET and in VBA. There is a strong
likelihood that Access will misunderstand what you mean. Consider renaming
the field in the table, in in any the queries, forms, reports, macros, or
code.

For a (lengthy) list of the names to avoid, see:
Problem names and reserved words
at:
http://allenbrowne.com/AppIssueBadWord.html
 

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