How do I go to a certain record and not the first one when opening my form? (1 Viewer)

Elyso

New member
Local time
Today, 14:55
Joined
Aug 31, 2009
Messages
8
I have a form which has an OnClose event handler connected...

Code:
Private Sub Report_Close()

DoCmd.OpenForm "MyFormName"

End Sub

What it does is simply to open the form called MyFormName but of course the first record will be displayed and that is not optimal.

I have an ID number which is the primary key (called "ID_B") for the form stored in a public variable called "MyPublicVar". It is also the record number "MyPublicVar" in the form that I would like to display when closing the report....

How can I achieve this?

Maybe I can add a "DoCmd.GoToRecord...." line after the above "DoCmd OpenForm" code (even though I am not knowledgable enough to know what that line should look like...

Perhaps there is a smarter solution?

Any help will be appreciated.
 

petehilljnr

Registered User.
Local time
Today, 05:55
Joined
Feb 13, 2007
Messages
192
Use the "Where" option on the OpenForm command.

Code:
Docmd.OpenForm "MyFormName",acNormal,,"ID_B = " & [COLOR=red][B]MyPublicVar[/B][/COLOR]

Assuming MyPublicVar is a number. If not, then you'd have to wrap it in single quotes (for text) or # for a date.
 

Users who are viewing this thread

Top Bottom