PC Review


Reply
Thread Tools Rate Thread

Add new records

 
 
Saintsman
Guest
Posts: n/a
 
      15th Aug 2008
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
 
Reply With Quote
 
 
 
 
Alex Dybenko
Guest
Posts: n/a
 
      15th Aug 2008
Hi,
after opening the form you can run:
DoCmd.GoToRecord , , acNext
and it will go to a new record

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com

"Saintsman" <(E-Mail Removed)> wrote in message
news:5A31B139-105C-46F1-BB53-(E-Mail Removed)...
>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


 
Reply With Quote
 
strive4peace
Guest
Posts: n/a
 
      15th Aug 2008


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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieve records, and all records joined to those records, etc., e Peter Stone Microsoft Access Queries 2 12th Jun 2009 05:41 AM
How to Form/Subform automatically duplicate records everytime I update records. ylho Microsoft Access Forms 0 6th Jun 2006 11:48 PM
to Duane Hookom - how to use Pivot Charts for individual records instead of summing all records Harold Good Microsoft Access Reports 1 21st Dec 2005 06:26 PM
Nslookup query for NS records returns all of the NS records, but not all of the Host records Bob Microsoft Windows 2000 Networking 1 8th Nov 2004 07:03 PM
Nslookup query for NS records returns all of the NS records, but not all of the Host records Bob Microsoft Windows 2000 DNS 2 7th Nov 2004 04:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:09 AM.