how toOpen form for current ID then navigate to other record

siamandm
BronzeLounger
Posts: 1259
Joined: 01 May 2016, 09:58

how toOpen form for current ID then navigate to other record

Post by siamandm »

Hi

if i have this code for opening a form for clicked ID

Code: Select all

DoCmd.OpenForm "frmName", acNormal, "", "[ID]=" & lngID, , acDialog
this open a form for the ID which i want, is its possible after I open the form give me the ability to navigate to other fields,

regards

User avatar
HansV
Administrator
Posts: 78613
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: how toOpen form for current ID then navigate to other re

Post by HansV »

No. You could do the following instead:

Change the line that opens the form to

Code: Select all

    DoCmd.OpenForm FormName:="frmName", WindowMode:=acDialog, OpenArgs:="[ID]=" & lngID
Add the following lines to the Form_Load event procedure of the form being opened (frmName):

Code: Select all

    If Not IsNull(Me.OpenArgs) Then
        DoCmd.SearchForRecord WhereCondition:=Me.OpenArgs
    End If
If you open the form normally, OpenArgs will be empty, and the DoCmd.SearchForRecord line will be skipped.
If you specify OpenArgs in the code that opens the form, DoCmd.SearchForRecord will use the condition passed in OpenArgs to move to the corresponding record, but the user will still be able to move to other records.
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1259
Joined: 01 May 2016, 09:58

Re: how toOpen form for current ID then navigate to other re

Post by siamandm »

you are Awesome Hans
much appreciated your all helps

many thanks