-
INSERT from Worksheet
Hi!
Im querying a range in excel worksheet, which I want to insert into an Access table.
The problem is that the recordset contains 26 Fields and the table just have 3. The first 2 fields in the set is always the same,
but field 3-26 is different and I want to create a row in the table for every field without writing INSERT INTO 24 times.
How can I Loop this in VBA/Excel?
szSQLEA = "SELECT * FROM [sheet1$A1:Z100]"
Set rsDataGet = New ADODB.Recordset
rsDataGet.Open szSQLEA, szConnectEA, adOpenForwardOnly, adLockReadOnly, adCmdText
Set objCommand = New ADODB.Command
objCommand.ActiveConnection = szConnectDB
If Not rsDataGet.EOF Then
objCommand.CommandText = "INSERT INTO Prognosis (ID,NAME,TIME) " & _
"VALUES('" & rsData.Fields(0).Value & "','" & rsData.Fields(1).Value & "','????');"
objCommand.Execute RecordsAffected:=lRecordsAffected, Options:=adCmdText Or adExecuteNoRecords
rsDataGet.MoveNext
End If
/Bjso