New at this...I'm trying to Export a query to a .txt file and I created this code based on a code I found online...I've tried a million different things and I always get the same error "invalid argument," I've thought through a few potential problems but to no avail...for instance...originally i didn't have the Cdate before the date column and I thought this was a sure fix since my date column is a varchar datatype. I then tried taking the #'s out from around the control references and it worked!...at least the .txt file was created but their was no data in the file!!! The #'s establish that the control reference is a date datatype...right? so I don't know why this would help. This is driving me crazy, can someone please help??? Thanks SO MUCH in advance! Here is the code:
Private Sub Command17_Click()
Dim PageName As String
On Error GoTo Err_Command17_Click
Dim rst As DAO.Recordset
Dim varArray As Variant
PageName = "I:\Shared_Retention\CCBatch\" & "CCBatch" & Format(Date, "MMDD") & ".txt"
Open PageName For Output As #1
Set rst = CurrentDb.OpenRecordset("Select * From dbo_creditcardrecords Where Cdate(Date)>=" & "#" & Forms!Reports!BeginningDate & "and Cdate(Date) <" & "#" & Forms!Reports!EndingDate & "#", dbSeeChanges)
While Not rst.EOF And Not rst.BOF
Print #1, rst
rst.MoveNext
Wend
Close #1
Exit_Command17_Click:
Exit Sub
Err_Command17_Click:
MsgBox Err.Description
Resume Exit_Command17_Click
End Sub
Private Sub Command17_Click()
Dim PageName As String
On Error GoTo Err_Command17_Click
Dim rst As DAO.Recordset
Dim varArray As Variant
PageName = "I:\Shared_Retention\CCBatch\" & "CCBatch" & Format(Date, "MMDD") & ".txt"
Open PageName For Output As #1
Set rst = CurrentDb.OpenRecordset("Select * From dbo_creditcardrecords Where Cdate(Date)>=" & "#" & Forms!Reports!BeginningDate & "and Cdate(Date) <" & "#" & Forms!Reports!EndingDate & "#", dbSeeChanges)
While Not rst.EOF And Not rst.BOF
Print #1, rst
rst.MoveNext
Wend
Close #1
Exit_Command17_Click:
Exit Sub
Err_Command17_Click:
MsgBox Err.Description
Resume Exit_Command17_Click
End Sub