1
背景:
我需要打开一个Access文件并获取信息在那里,以与我的Excel电子表格中的数据进行比较。
我正在使用Microsoft Office 15.0 Access数据库引擎对象库而不是Microsoft DAO对象库。
问题:
虽然我可以用下面的代码粘贴所有的数据,出于某种原因,它开始在“行2”忽略标题。在Excel中Accesss搜索标题在访问数据库
Sub Sample()
Const PathToDB = "C:\...\AccessFile.accdb"
Const TitleSampleTable = "Sample Table"
Dim BDSample As Database
Dim SampleTable As Recordset
Dim SampleTableDef As TableDef
Dim CounterTitles As Long
Dim CounterRows As Long
Dim ColToPasteIn As Long
Dim RowToPasteIn As Long
Set BDSample = DBEngine.Workspaces(0).OpenDatabase(PathToDB)
Set SampleTable = BDSample.OpenRecordset(TitleSampleTable, dbOpenDynaset)
Set SampleTableDef = BDSample.TableDefs(TitleSampleTable)
For CounterTitles = 0 To SampleTableDef.RecordCount
RowToPasteIn = RowToPasteIn + 1
ColToPasteIn = 1
For CounterRows = 0 To SampleTable.Fields.Count
With Sheets(TitleSampleTable)
.Cells(RowToPasteIn, ColToPasteIn).Value = SampleTable.Fields(CounterRows) 'this is starts in the "body" of access, I can't figure a way to retrieve titles!
ColToPasteIn = ColToPasteIn + 1
End With
Next CounterRows
SampleTable.MoveNext
Next CounterTitles
Set BDSample = Nothing
Set SampleTable = Nothing
Set SampleTableDef = Nothing
End Sub
的样本数据
样本数据
问题:
我如何GE t的标题值?
哈哈,够简单吧!谢谢! – Sgdva