Copy Records

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

I want to copy a record from a table, then change one field value. How
can I do this?

Copy Record
Insert Record
Change One Field to a different value from an Unbound Textbox
Save Record

I guess this is the order I would do this in.

Thanks
DS
 
There are many ways to do what you want. One way for single form or continous
forms view would be to add a button in the form header with code in the
"Click" event.

Or for datasheet view (or continous forms view) the code would go in the
FORM "double click" event.

In the code you would:
Dim strSqL as string
Dim a variable for each field in the table you want to copy
Dim a variable for the unbound text box

Store the unbound text box value in the variable for the ub text box,
converting to the correct datatype (using CSng(), CDate(), CInt(),...) .
Trap for ub text box errors (Null, wrong data, etc)
Read the current record field values into the variables.

Create the strSQL string:

strSQL = "INSERT INTO MyTable (field1, field2, ... ,fieldn) VALUES (" & var1
& ", " & " #" & var2 & "#, '" & var3 & "', " & varN & ")"

(use the correct delimiters for the datatypes. change MyTable and field1..
to your names)

When you get to the field you want to change, use the ub text box variable.
Insert (append) the data using:

Currentdb.Execute strSQL , dbFailOnError


Like I said, there are many ways; this is how I would do it.
 
Back
Top