hi to all
I have code for export query to text file:
Dim db As Database, rst As Recordset, SQL As String
Dim a As Integer, AccCode, OrderNo, Myfile As String
Set db = CurrentDb
Myfile = "C:\test.txt"
SQL = "SELECT Employees.FirstName, Employees.LastName, Employees.DepartmentID FROM Employees WHERE (((Employees.DepartmentID)>1));"
Set rst = db.OpenRecordset(SQL)
rst.MoveLast
rst.MoveFirst
Open Myfile For Output As #1
For a = 1 To rst.RecordCount
AccCode = Trim(rst!FirstName) & Space(10 - Len(Trim(rst!FirstName)))
OrderNo = Trim(rst!LastName) & Space(25 - Len(Trim(rst!LastName)))
Print #1, AccCode & OrderNo
rst.MoveNext
Next
Close #1
rst.Close
db.Close
and i create form with 1 button so when u click on that button is nead to make text file. but is give me run-time '13'error :
Type Mismatch
on line :Set rst = db.OpenRecordset(SQL)
Maybe i make code on wrong place?
and how to make header and footer fot text file?
Thanks
Fule
I have code for export query to text file:
Dim db As Database, rst As Recordset, SQL As String
Dim a As Integer, AccCode, OrderNo, Myfile As String
Set db = CurrentDb
Myfile = "C:\test.txt"
SQL = "SELECT Employees.FirstName, Employees.LastName, Employees.DepartmentID FROM Employees WHERE (((Employees.DepartmentID)>1));"
Set rst = db.OpenRecordset(SQL)
rst.MoveLast
rst.MoveFirst
Open Myfile For Output As #1
For a = 1 To rst.RecordCount
AccCode = Trim(rst!FirstName) & Space(10 - Len(Trim(rst!FirstName)))
OrderNo = Trim(rst!LastName) & Space(25 - Len(Trim(rst!LastName)))
Print #1, AccCode & OrderNo
rst.MoveNext
Next
Close #1
rst.Close
db.Close
and i create form with 1 button so when u click on that button is nead to make text file. but is give me run-time '13'error :
Type Mismatch
on line :Set rst = db.OpenRecordset(SQL)
Maybe i make code on wrong place?
and how to make header and footer fot text file?
Thanks
Fule