Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy one record to another table via a form.

Status
Not open for further replies.

lin

IS-IT--Management
Aug 27, 2000
13
0
0
US
I have a table with 1800 records. I want to search for a specific record via a form and then have that record copied to another table (table 2).

Every evening I want to run a report that prints out table 2 and then erases all of the data in it.

Any help is greatly appreciated!
 
Hi lin, from the rating you gave these forums you seem disapointed. What could we do to improve your rating?

Getting clear, easy to understand answers to questions is usually accomplished only with quite an exchange of information.

If you are just starting to use code to make changes to tables this might seem somewhat dificult. However the learning curve for this type of code is easy!

Your request seems very straight forward, but in order to give you some help we will probably need to ask several questions of you about your tables, "do they have the same number of fields?, are the fields the same datatype, and so on.

Listed below is an example I just ran on a couple sample tables. If you have questions regarding this example feel free to email them or post them here.

This example assumes that Table1 and Table 2
each have fields named Field1 and Field2 and
that both tables have the same data type for Field1 and 2

This example form is bound to Table1.
When the record you want to copy to Table2
is displayed on your form, click the button
named Command0 and the values of Field1 and Field2
from the current record will be inserted into Table2.

Private Sub Command0_Click()

Dim db As Database
Dim rs As Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("Table2")

'the ( Me.Field1 ) is a field on my form that I want to
'include in the new record in table 2
'the ( !Field1 ) is the field in table 2 that
'is getting the data.

With rs
.AddNew
!Field1 = Me.Field1
!Field2 = Me.Field2
.Update
End With

rs.Close
Set db = Nothing

End Sub
 
Thanks to everyone who responded to my plea for help! I finally got it to work!!!! [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top