Access VBA - method or data member not found error

2019-09-07 14:26发布

I'm new to Access and thank you for reading this first.

I'm exporting a query in Access to a pipe delimited CSV file. The query is from a table which is ODBCed from SQL.

I've been getting for the line dbs.Recordset : Method or data member not found error.

Huge thanks for any suggestion to fix this.

Option Compare Database
Option Explicit

Sub Command12_Click()
Dim dbs As DAO.database 
Dim rst As DAO.Recordset
Dim intFile As Integer
Dim strFilePath As String
Dim intCount As Integer
Dim strHold

strFilePath = "C:\temp\TEST.csv"

Set dbs = CurrentDb

Set rst = db.OpenRecordset("T_Export_CSV", dbOpenForwardOnly)

intFile = FreeFile


Open strFilePath For Output As #intFile

Do Until rst.EOF
   For intCount = 0 To rst.Fields.Count - 1
   strHold = strHold & rst(intCount).Value & "|"
   Next
   If Right(strHold, 1) = "|" Then
      strHold = Left(strHold, Len(strHold) - 1)
   End If
   Print #intFile, strHold
   rst.MoveNext
   strHold = vbNullString
Loop

Close intFile
rst.Close
Set rst = Nothing

MsgBox ("Export Completed Successfully")
End Sub

Thank you so so much for your time and please leave any comment below for any clarification if needed. I will try my best to be responsive!

1条回答
等我变得足够好
2楼-- · 2019-09-07 14:54

Office 15.0 object library is the one you need to include in the references for O365 objects or Office 2013 Access VBA

查看更多
登录 后发表回答