Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

Trouble adding another print statement to VB 6.0

I have a VB 6.0 function which takes a ResultSet and prints the entire contents to a textfile.  But I wanted to print the filename in the first line of the textfile.

When I added an additional print statement (see arrows below), it would not compile.  And unfortunately it does not give me the error.

Can anyone find the problem?

thanks,
newbieweb

Public Sub CopyRsToCSV(ByVal prstData As ADODB.Recordset, Optional ByVal userFilename As String)
Dim intFileNumber As Integer
Dim lngLoop1 As Long
Dim lngLoop2 As Long
Dim strX As String
Dim pstrFilename As String

    'If Len(Trim$(pstrFilename)) = 0 Then
    pstrFilename = App.Path & "\" & userFilename
   
    'Open data file data to file
    intFileNumber = FreeFile   ' Get unused file
    >>>> Print #intFileNumber, userFilename <<<< New line: won't compile
    Open pstrFilename For Output As #intFileNumber
    'Write data to file
    With prstData
        strX = ""
        For lngLoop1 = 0 To .Fields.Count - 1
            strX = strX & .Fields(lngLoop1).Name & """, """
        Next lngLoop1
        Print #intFileNumber, strX
        strX = ""
        For lngLoop2 = 0 To .Fields.Count - 1
            strX = strX & .Fields(lngLoop2).Type & """, """
        Next lngLoop2
        Print #intFileNumber, strX
        If .RecordCount > 0 Then .MoveFirst
        Do Until .EOF
            strX = ""
            For lngLoop = 0 To .Fields.Count - 1
                strX = strX & .Fields(lngLoop).Value & """, """
            Next lngLoop
            Print #intFileNumber, strX
            .MoveNext
        Loop
    End With
    Close
    On Error Resume Next
    Close #intFileNumber
    If Err <> 0 Then
        MsgBox ("Error: " & Err.Description)
    'Else
     '   MsgBox ("No error")
    End If
    On Error GoTo 0
End Sub
0
newbieweb
Asked:
newbieweb
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:

you tried to print into the file BEFORE opening it:

Public Sub CopyRsToCSV(ByVal prstData As ADODB.Recordset, Optional ByVal userFilename As String)
Dim intFileNumber As Integer
Dim lngLoop1 As Long
Dim lngLoop2 As Long
Dim strX As String
Dim pstrFilename As String

    'If Len(Trim$(pstrFilename)) = 0 Then
    pstrFilename = App.Path & "\" & userFilename
   
    'Open data file data to file
    intFileNumber = FreeFile   ' Get unused file
    Open pstrFilename For Output As #intFileNumber
    Print #intFileNumber, userFilename
    'Write data to file
    With prstData
        strX = ""
        For lngLoop1 = 0 To .Fields.Count - 1
            strX = strX & .Fields(lngLoop1).Name & """, """
        Next lngLoop1
        Print #intFileNumber, strX
        strX = ""
        For lngLoop2 = 0 To .Fields.Count - 1
            strX = strX & .Fields(lngLoop2).Type & """, """
        Next lngLoop2
        Print #intFileNumber, strX
        If .RecordCount > 0 Then .MoveFirst
        Do Until .EOF
            strX = ""
            For lngLoop = 0 To .Fields.Count - 1
                strX = strX & .Fields(lngLoop).Value & """, """
            Next lngLoop
            Print #intFileNumber, strX
            .MoveNext
        Loop
    End With
    Close
    On Error Resume Next
    Close #intFileNumber
    If Err <> 0 Then
        MsgBox ("Error: " & Err.Description)
    'Else
     '   MsgBox ("No error")
    End If
    On Error GoTo 0
End Sub



0
 
newbiewebSr. Software EngineerAuthor Commented:
I should have at least TRIED to read the VB.

Thanks,
newbieweb
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now