Hello,
I am trying to create a txt file to import into our accounting software. I get the file (its blank), but it fails on the WriteLine and i get the run time error. I have a command button on a form that the user will click to export the file. Any help would be greatly appreciated.
Private Sub cmdExport_Click()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strPath As String
Dim strPathGB As String
Dim strPathGG As String
Dim strSql As String
Dim flGB
Dim flGG
Set cnn = CurrentProject.Connection
strSql = "Select * from tblAPExport Where Left(GLNumber,2) <> '11' And InvoiceImport = 0 And Closed = 0"
rst.Open strSql, cnn, adOpenDynamic, adLockOptimistic
If Not (rst.EOF) Then
rst.MoveFirst
strPath = "K:\Accounts Payable\PO Database Export\"
strPathGB = strPath & "GB - "
strPathGG = strPath & "GG - "
Set fso = CreateObject("Scripting.FileSystemObject")
Set flGB = fso.CreateTextFile(strPathGB & Format(Date, "mm-dd-yy") & ".txt", True)
'Set flGG = fso.CreateTextFile(strPathGG & Format(Date, "mm-dd-yy") & ".txt", True)
Do Until rst.EOF
f1GB.WriteLine rst!Invoice & rst!VendorNumber
rst.MoveNext
Loop
flGB.Close
End If
End Sub
I am trying to create a txt file to import into our accounting software. I get the file (its blank), but it fails on the WriteLine and i get the run time error. I have a command button on a form that the user will click to export the file. Any help would be greatly appreciated.
Private Sub cmdExport_Click()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strPath As String
Dim strPathGB As String
Dim strPathGG As String
Dim strSql As String
Dim flGB
Dim flGG
Set cnn = CurrentProject.Connection
strSql = "Select * from tblAPExport Where Left(GLNumber,2) <> '11' And InvoiceImport = 0 And Closed = 0"
rst.Open strSql, cnn, adOpenDynamic, adLockOptimistic
If Not (rst.EOF) Then
rst.MoveFirst
strPath = "K:\Accounts Payable\PO Database Export\"
strPathGB = strPath & "GB - "
strPathGG = strPath & "GG - "
Set fso = CreateObject("Scripting.FileSystemObject")
Set flGB = fso.CreateTextFile(strPathGB & Format(Date, "mm-dd-yy") & ".txt", True)
'Set flGG = fso.CreateTextFile(strPathGG & Format(Date, "mm-dd-yy") & ".txt", True)
Do Until rst.EOF
f1GB.WriteLine rst!Invoice & rst!VendorNumber
rst.MoveNext
Loop
flGB.Close
End If
End Sub