Open Access Form with particular record displayed

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
tpigielskiAsked:
Who is Participating?
 
omgangConnect With a Mentor Commented:
Pass a Where expression with the OpenForm command to open the form to the specified record.

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

OM Gang
0
 
omgangCommented:
See VBA Help for OpenForm Method of DoCmd command.

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

OM Gang
0
All Courses

From novice to tech pro — start learning today.