~ VBA Export to text file
I have spent a number of hours on this problem but can't see what I'm doing wrong. Any help or direction anyone can give me will be greatly appreciated.
Table: tbl_Users
Multiple fields, but only one for this test
Field: myUsers
a 15 character text field
Debug.Print returns the correct expected information.
The code works perfectly until I try to export to a text file.
Export specification: dbUsers
works perfectly manually
is correctly in MSysImexSpecs and MSysImexColumns tables
However, I get an error trying to export to a text file in VBA:
2498 : An expression you entered is the wrong data type for one of the arguments.
'~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Private Sub cmd_Run2_Click()
On Error GoTo ErrorHandler
Dim myDB As Database
Dim qdfEmail As QueryDef
Dim rstEmail As Recordset
Dim strSQL As String
strSQL = "SELECT tbl_Users.myUsers "
strSQL = strSQL & "FROM tbl_Users "
strSQL = strSQL & "ORDER BY tbl_Users.myUsers;"
Set myDB = CurrentDb()
Set qdfEmail = myDB.CreateQueryDef("", strSQL)
Set rstEmail = qdfEmail.OpenRecordset(dbOpenDynaset, dbReadOnly)
rstEmail.MoveLast
rstEmail.MoveFirst
Debug.Print rstEmail.RecordCount
Do While Not rstEmail.EOF
Debug.Print rstEmail!myUsers.Value
rstEmail.MoveNext
Loop
DoCmd.TransferText acExportDelim, "dbUsers", rstEmail, "C:\myAccess\expSQL.txt"
rstEmail.Close
qdfEmail.Close
myDB.Close
Set rstEmail = Nothing
Set qdfEmail = Nothing
Set myDB = Nothing
Exit_Routine:
Exit Sub
ErrorHandler:
MsgBox Err & " : " & Err.Description
Resume Exit_Routine
End Sub
'~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
db
~
~*~*~*~*~*~
Excederin Headache Number 2498
~*~*~*~*~*~
I have spent a number of hours on this problem but can't see what I'm doing wrong. Any help or direction anyone can give me will be greatly appreciated.
Table: tbl_Users
Multiple fields, but only one for this test
Field: myUsers
a 15 character text field
Debug.Print returns the correct expected information.
The code works perfectly until I try to export to a text file.
Export specification: dbUsers
works perfectly manually
is correctly in MSysImexSpecs and MSysImexColumns tables
However, I get an error trying to export to a text file in VBA:
2498 : An expression you entered is the wrong data type for one of the arguments.
'~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Private Sub cmd_Run2_Click()
On Error GoTo ErrorHandler
Dim myDB As Database
Dim qdfEmail As QueryDef
Dim rstEmail As Recordset
Dim strSQL As String
strSQL = "SELECT tbl_Users.myUsers "
strSQL = strSQL & "FROM tbl_Users "
strSQL = strSQL & "ORDER BY tbl_Users.myUsers;"
Set myDB = CurrentDb()
Set qdfEmail = myDB.CreateQueryDef("", strSQL)
Set rstEmail = qdfEmail.OpenRecordset(dbOpenDynaset, dbReadOnly)
rstEmail.MoveLast
rstEmail.MoveFirst
Debug.Print rstEmail.RecordCount
Do While Not rstEmail.EOF
Debug.Print rstEmail!myUsers.Value
rstEmail.MoveNext
Loop
DoCmd.TransferText acExportDelim, "dbUsers", rstEmail, "C:\myAccess\expSQL.txt"
rstEmail.Close
qdfEmail.Close
myDB.Close
Set rstEmail = Nothing
Set qdfEmail = Nothing
Set myDB = Nothing
Exit_Routine:
Exit Sub
ErrorHandler:
MsgBox Err & " : " & Err.Description
Resume Exit_Routine
End Sub
'~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
db
~
~*~*~*~*~*~
Excederin Headache Number 2498
~*~*~*~*~*~