Run time error 424 object required

bmorse

New member
Local time
Today, 17:00
Joined
Jun 12, 2015
Messages
7
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
 
flgb or f1gb?

You should have

Option Explicit

at the top of your module, to avoid BS like this
 
There are two objects on the WriteLine - the flGB object and the rst object. If you set a breakpoint on the WriteLine and then open up the locals window before you click your button, you will be able to see which of those two variables is undefined. That will be half the battle right there.

Also, are the two objects you are writing both in text/string format?
 
Paul,
Its flGB

spikepl was the one that asked, and asked because you set one variable and then use the other, likely the source of your error.
 
So i did the option explicit and named my variables. now i get compile error: object required at the set flGB line. the only thing that comes up in the locals window is the reference to the export button. both of those rst fields are text. thanks so much for your help!
 

Users who are viewing this thread

Back
Top Bottom