Thread: Excel to SQL
View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
OfficeHacker OfficeHacker is offline
external usenet poster
 
Posts: 14
Default Excel to SQL

Hi Jani,

Transferring data from Excel to SQL Server via a linked Access table should
work (I've done it before) although I used an Access query (QueryDef object)
rather than opening the recordset.

Some things to look at:
- confirm your privileges on the SQL Server database for the table you are
trying to update. Confirm your account has read/write privileges.

- Don't use the OpenRecordset method on the query. This is an action query
(remember, you're appending). For this use the Execute method instead,
like this:

Dim dibs As DAO.Database
Dim qdf As DAO.QueryDef

Set dbs = CurrentDb()
Set qdf = dbs.QueryDefs("qryMyAppendQuery")

qdf.Parameters("Sent1") = Range("A" & r).Value
qdf.Parameters("Date1") = Range("B" & r).Value
'etc...

qdf.Execute

- There is no data validation. How do you guarantee that
".Fields("Date1") = Range("B" & r).Value" is being appended with a valid
date value. Passing incorrect data types will certainly generate an error.