Open Access Form with particular record displayed

tpigielski
tpigielski used Ask the Experts™
on
I have an Access 2007 form that is opened (by default) on a new record.  The code in the "On Load" event for the form is as follows:

    DoCmd.GoToRecord acDataForm, Me.Name, acNewRec

What I would like to do is open the form, optionally, at a particular record.  I cannot use the "gotorecord" method, because, as I read things, a value specified (instead of the acNewRec  parameter), is an offset.  I want to be able to go to a record based on a primary key value in a table used to populate the form.

Thanks for your help.

Tom
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Manager
Commented:
Pass a Where expression with the OpenForm command to open the form to the specified record.

DoCmd.OpenForm FormName, , , "PKValue = " & ThePKValue

OM Gang
omgangIT Manager

Commented:
See VBA Help for OpenForm Method of DoCmd command.

expression.OpenForm(FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)

OM Gang

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial