instead of setting the WHERE parameter of OpenForm, you can send the ID
as an OpenArg. In the form Load event, if the ID is not found, then
place the user on a new record
to open a form and send the ID as an OpenArg:
DoCmd.OpenForm "Formname", , , , , , me.[ID]
~~
on the LOAD event of Formname, put this code:
'~~~~~~~~~~~~~~~~~
Dim lngID As Long
If Len(Trim(Nz(Me.OpenArgs, ""))) > 0 Then
lngID = CLng(Me.OpenArgs)
If lngID <> 0 Then
Me.RecordsetClone.FindFirst "ID_fieldname=" & lngID
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
else
If Not Me.NewRecord Then
DoCmd.RunCommand acCmdRecordsGoToNew
End If
End If
End If
'~~~~~~~~~~~~~~~~~
WHERE
ID_fieldname is the name of your ID field
btw, you should qualify your ID field such as SalesID, CustID, ... using
ID as a fieldname without describing it is ambinguous and makes for some
pretty confusing code and queries!
Warm Regards,
Crystal
remote programming and training
Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace
*
(: have an awesome day

*
Saintsman wrote:
> I have a form projindex which users enter records
> There is a library field where users pick from a library - this has a popup
> form on click event to allow them to select a library item - the pop up
> library form has list boxes & filters and its source is the same table as
> projindex. This works OK when I have an existing record & want to change the
> library item, but how do I add a new record by code & should this be on the
> projindex form or the popup form
> current code is:
>
> DoCmd.OpenForm "subprojpopup", , , "id = " & Me!ID
>
> I assume I need some code that if new record then addnew, else
> docmd.openform etc
>
> Thank very much