Sub 调用ACCESS数据库查询()Dim rst As New ADODB.RecordsetDim myPath As StringDim SQL As StringDim i As IntegermyPath = ThisWorkbook.Path & "\新建 Microsoft Access 数据库 (4G-2G).accdb"cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & myPath ‘’调用ACCESS数据库SQL = "SELECT mecontext,optionalfeatUrelicense,featurestate,licensestate FROM [OPT] where [OptionalFeatureLicense] like '%mul%'" ‘’‘’查询数据库rst.Open SQL, cnn, adOpenKeyset, adLockOptimisticCells.ClearContents ‘’‘清空表格For i = 0 To rst.Fields.Count - 1’‘’‘’‘’建立表头Cells(1, i + 1) = rst.Fields(i).NameNextRange("A2").CopyFromRecordset rstrst.Closecnn.CloseSet rst = NothingEnd Sub
如果觉得《VBA+ADO查询ACCESS数据库》对你有帮助,请点赞、收藏,并留下你的观点哦!