Command button to copy records

K

kevlowe1

Hello, I require some assistance in a macro or code that will allow the
user to press a command button and copy certian fields of that record
into a new record. I am an novice to code writing so please excuse any
follow up questions.
 
L

Linda Burnside

You could try something like this:

Dim strTextBox1 as String
Dim strTextBox2 as String
Dim strSQL as String

strTextBox1 = Me.TextBox1.value
strTextBox2 = Me.TextBox2.value

strsQL = "INSERT INTO myTable ( Field1, Field2 ) " & _
"SELECT '" & strTextBox1 & "' AS Expr1, '" & strTextBox2 & "' AS Expr2 "
DoCmd.RunSQL strSQL

After you run this code, you would probably want to use code to jump to the
record you just added so that you could make changes/additions to the data.

Linda
 
K

kevlowe1

I tried what you suggested and I'm not getting very far. Let me try to
be more specific. The table that I am using is called Call Sheet. On
the form, I want the command button to copy the the following fields
from the current record being displayed: Date, Department, Work Order
#, Team Leader, Priority, Machine #, Work Order #, and Description.
Thank you for hour help.

Kevin
 
L

Linda Burnside

If your primary key is not something simple like an autonumber, you may have
to remember to include your primary key in the insert statement.

Linda
 
Top