Results 1 to 4 of 4

Thread: Help with Run-Time error '3709'

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    61

    Help with Run-Time error '3709'

    I've been working on a program that appears to work fine but for some unexplained reason I get a
    Run-Time error '3709' The connection cannot be used to perform this operation. It is either closed or invalid in this context.

    This part of the program exports records it find that match the Export by filter

    The error appears when I select Export by Entity.

    Here is my code - Anyone see anything?
    HTML Code:
    Private Sub cmdExport_Click()
        Dim lRS As New ADODB.Recordset
        Dim x As ListItem
        Dim thefile As String
        Dim lData As String, lSeparator As String
        
        CommonDialog1.FileName = ""
        CommonDialog1.DialogTitle = "Save As Text File"
        CommonDialog1.Filter = "CSV Files (*.csv)|*.csv|Text Files (*.txt)|*.txt|All Files (*.*)|*.*|"
        CommonDialog1.ShowSave
        thefile = CommonDialog1.FileName
        If thefile <> "" Then
            If Option1.Value Then
                lSeparator = "|"
            ElseIf Option2.Value Then
                lSeparator = ","
            ElseIf Option3.Value Then
                lSeparator = ", "
            ElseIf Option4.Value Then
                lSeparator = vbTab
            ElseIf Option5.Value Then
                lSeparator = txtOther.Text
            End If
            
            lRS.Open "select * from tblEntries order by fldEntity", gConn, adOpenStatic, adLockReadOnly
            'check if there are records
            If Not lRS.EOF Then
                lData = "Entity" & lSeparator & "Unit" & lSeparator & "Observer" & lSeparator & "Month" & lSeparator & "Year" & lSeparator & "Typehealthcare" & lSeparator & "Patientcontact" & lSeparator & "Compliance" & lSeparator & "Gown" & lSeparator & "Gloves" & lSeparator & "Surgicalmask" & lSeparator & "N95mask" & vbCrLf
                While Not lRS.EOF
                    lData = lData & lRS.Fields("fldEntity").Value & lSeparator & lRS.Fields("fldUnit").Value & lSeparator & lRS.Fields("fldObserver").Value & lSeparator & Format$(CDate(lRS.Fields("fldMonth").Value & "/1/" & lRS.Fields("fldYear").Value), "mmm") & lSeparator & lRS.Fields("fldYear").Value & lSeparator & _
                        lRS.Fields("fldHealthcareWorkerType").Value & lSeparator & lRS.Fields("fldPatientContact").Value & lSeparator & lRS.Fields("fldCompliance").Value & lSeparator & lRS.Fields("fldGown").Value & lSeparator & lRS.Fields("fldGloves").Value & lSeparator & lRS.Fields("fldSurgicalMask").Value & lSeparator & lRS.Fields("fldN95Mask").Value & vbCrLf
                    lRS.MoveNext
                Wend
                If lRS.State <> adStateClosed Then lRS.Close
                'Save data to file
                Call SaveStringToFile(lData, thefile)
                MsgBox "Done export.", vbInformation, g_AppName
            Else
                MsgBox "No record found.", vbExclamation, g_AppName
            End If
        End If
    End Sub

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Help with Run-Time error '3709'

    Quote Originally Posted by steve1040 View Post
    The error appears when I select Export by Entity.
    What is "Export By Entity"

    I dont' see anything that says "Export By Entity"

    I even copy and pasted your entire code into a word document and then did a search on "Export By Entity" and Word couldn't find it.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Help with Run-Time error '3709'

    Quote Originally Posted by Hack View Post
    What is "Export By Entity"

    I dont' see anything that says "Export By Entity"

    I even copy and pasted your entire code into a word document and then did a search on "Export By Entity" and Word couldn't find it.
    It's probably the caption on cmdExport.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Help with Run-Time error '3709'

    Yeah...that is a possibility I didn't think of. I thought he was referring to a particular option within the code itself.

    However, if this is true, and it is nothing more than text on a button, then we would need to know what line of code in the routine is causing the error? Also, does it happen no matter which of the options is select?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width