Export value from Excel worksheet to Access record

梦想的初衷 提交于 2020-01-14 05:54:33

问题


I have an excel spreadsheet that contains the primarky-key/id value for a record in a table in an access database.

I would like to export specific data from certain cells in the spreadsheet to certain fields in the corresponding record in the table.

Is this possible, any help would be greatly appreciated.

Many thanks

Noel


回答1:


You can use ADO with Excel and Access. You can either open an Access recordset and update or add fields (columns) and records one by one, or you can use an SQL statement with IN key word or an internal connection string.

Very roughly:

strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\docs\mydb.mdb"

Set cn = CreateObject("ADODB.Connection")

cn.Open strCon

strSQL="SELECT * INTO NewTable  FROM [Sheet1$] IN '' " _
  & "[Excel 8.0;HDR=YES;IMEX=2;DATABASE=C:\Docs\WB.xls]"

cn.Execute strSQL


来源:https://stackoverflow.com/questions/3000972/export-value-from-excel-worksheet-to-access-record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!