By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,748 Members | 1,300 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,748 IT Pros & Developers. It's quick & easy.

Copy current values to new record

P: n/a
I have read a previous entry and it really helped, but I keep getting an
error. The previous entry was:
If you mean you want to carry the current values of the controls
over into a new record to be entered using the same form then:

Look up DefaultValue using the Help system.
The easiest way to do that is to open a code module,
type defaultValue, place the cursor over the word and
hit F1.

After you have read that go here:

http://www.mvps.org/access/forms/frm0012.htm

then here:

http://www.mvps.org/access/forms/frm0027.htm

After you have read that try this:

Private Sub cmdSetDefaultValues_Click()
Dim ctl As Access.Control

On Error Resume Next

For Each ctl In Me.Controls
ctl.defaultValue = """" & ctl.Value & """"
Next

If Not ctl Is Nothing Then Set ctl = Nothing

End Sub
The error I keep getting is that the primary key or index cannot contain a
Null value. I have both the primary key and the foreign key on the form so I
think this may be affecting it, I guess. Is there a way I can exclude these
two controls from being copied into the new record?

Thanks,
Lee

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200705/1

May 23 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
There is a template button in the create button wizard

named Duplicat Record

There is alot of free examples on the following

http://www.access-forum.com/plus/viewforum.php?f=41

Use it
www.access-forum.com

DavidB :
On May 23, 12:07 pm, "cableguy47905" <u4349@uwewrote:
I have read a previous entry and it really helped, but I keep getting an
error. The previous entry was:

If you mean you want to carry the current values of the controls
over into a new record to be entered using the same form then:

Look up DefaultValue using the Help system.
The easiest way to do that is to open a code module,
type defaultValue, place the cursor over the word and
hit F1.

After you have read that go here:

http://www.mvps.org/access/forms/frm0012.htm

then here:

http://www.mvps.org/access/forms/frm0027.htm

After you have read that try this:

Private Sub cmdSetDefaultValues_Click()
Dim ctl As Access.Control

On Error Resume Next

For Each ctl In Me.Controls
ctl.defaultValue = """" & ctl.Value & """"
Next

If Not ctl Is Nothing Then Set ctl = Nothing

End Sub

The error I keep getting is that the primary key or index cannot contain a
Null value. I have both the primary key and the foreign key on the form so I
think this may be affecting it, I guess. Is there a way I can exclude these
two controls from being copied into the new record?

Thanks,
Lee

--
Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/databases-ms-access/2007...

Sure just wrap the line that sets the default with something along the
lines of

if (ctl.Name <"InsertNameOfContrlToBeExcludedHere") then
SET DEFAULT
endif

if you need to exclude more than one field AND them in the IF line.
May 26 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.