Is it possible to use an array to populate the values of a sql insert statement? i get an error, it seems that access thinks i am calling a function.
(Overall, the situation is that i need to import data from an excel spreadsheet into multiple access tables.
The problem is that only certain columns pertain to certain access tables.
The solution that i thought of was creating recordsets for each table, and storing the values of the recordsets into arrays, then using a SQL insert statement to insert the values into the tables......)
here's some of the code:
Dim varRecords As Variant
strsql = "Select CustomerName, customermainphone, billingaddressln1, billingaddressln2, billingcity, billingstate, billingzip, contactname, contactphone from orderform"
Set rec = db.OpenRecordset(strsql)
rec.MoveLast
intRecords = rec.recordCount
MsgBox intRecords
rec.MoveFirst
varRecords = rec.GetRows(intRecords)
For t = 1 To intRecords
x = 0
DoCmd.RunSQL ("INSERT into t_customers(CustomerName, customermainphone, billingaddressln1, billingaddressln2, billingcity, billingstate, billingzip, contactname, contactphone) VALUES( varRecords(x,y), varRecords(x+1,y), varRecords(x+2,y), varRecords(x+3,y), varRecords(x+4,y), varRecords(x+5,y), varRecords(x+6,y), varRecords(x+7,y), varRecords(x+8,y) ) ")
y = y + 1
rec.MoveNext
Next
i know this is crap, but i'm pretty new to all this, and can't think of any other way.
any advice would be greatly appreciated!!!
(Overall, the situation is that i need to import data from an excel spreadsheet into multiple access tables.
The problem is that only certain columns pertain to certain access tables.
The solution that i thought of was creating recordsets for each table, and storing the values of the recordsets into arrays, then using a SQL insert statement to insert the values into the tables......)
here's some of the code:
Dim varRecords As Variant
strsql = "Select CustomerName, customermainphone, billingaddressln1, billingaddressln2, billingcity, billingstate, billingzip, contactname, contactphone from orderform"
Set rec = db.OpenRecordset(strsql)
rec.MoveLast
intRecords = rec.recordCount
MsgBox intRecords
rec.MoveFirst
varRecords = rec.GetRows(intRecords)
For t = 1 To intRecords
x = 0
DoCmd.RunSQL ("INSERT into t_customers(CustomerName, customermainphone, billingaddressln1, billingaddressln2, billingcity, billingstate, billingzip, contactname, contactphone) VALUES( varRecords(x,y), varRecords(x+1,y), varRecords(x+2,y), varRecords(x+3,y), varRecords(x+4,y), varRecords(x+5,y), varRecords(x+6,y), varRecords(x+7,y), varRecords(x+8,y) ) ")
y = y + 1
rec.MoveNext
Next
i know this is crap, but i'm pretty new to all this, and can't think of any other way.
any advice would be greatly appreciated!!!