Tech Support Guy banner
Status
Not open for further replies.
1 - 5 of 5 Posts

·
Registered
Joined
·
2 Posts
Discussion Starter · #1 ·
I am adding some extra functionalities to an existing MS Access 2003 database. I would like to have a button, that copies some of the values of the current record that is open in the form, and pastes it into a new record.

So if I would have a field called 'year', with the value '2009', I would like to have this same value '2009' pasted into the same field in a new record (I would like a seperate 'new record' button for this, using VB).

Anyone can help me in accomplishing this? Help is very much appreciated! :up:
 

·
Registered
Joined
·
19,896 Posts
Koen, welcome to the Forum.
The way to do this as to assign your current Field's value to a Variable, go to the new record and then assign the variable's value to the Field.
So the the VBA Code would look like this

Dim tempvalue as string
tempvalue = me.year
DoCmd.GoToRecord , , acNext
me.year = tempvalue

where year is the actual name of your Field, if the value in the Field is a real date you would need to use
Dim tempvalue as Date.
 

·
Registered
Joined
·
94 Posts
In the button click sub, do this:

Dim rs as Recordset
Set rs=me.recordset
rs.addnew
rs!year = textbox1.value 'assuming textbox1 contains the year value
rs.update
rs.close


That should get you close to what you're after, methinks. I haven't tested the code, but I think it's right.
 

·
Registered
Joined
·
2 Posts
Discussion Starter · #5 ·
Hi,

Thanks a lot, this worked!

I have basic MSAccess knowledge, but my programming skills are still a bit lacking. Your help is much appreciated! :)
 
1 - 5 of 5 Posts
Status
Not open for further replies.
Top