Results 1 to 7 of 7

Thread: need help with deleting file from folder

  1. #1

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    need help with deleting file from folder

    How can I delete the file associated with this id? The path is not correct. Do I need to put the objRs!n_pdfname into a variable first?
    VB Code:
    1. Call CreateConnection(objConn)
    2.  
    3.     Set objRs = New ADODB.Recordset
    4.  
    5.     objRs.ActiveConnection = objConn
    6.     objRs.CursorLocation = adUseClient
    7.     objRs.CursorType = adOpenDynamic
    8.     objRs.LockType = adLockOptimistic
    9.     objRs.Source = "select * from Documents where n_id='" & MSFlexGrid1.Text & "'"
    10.     objRs.Open
    11.  
    12.     Dim Msg
    13.     Msg = "Do you really want to delete this Document?"
    14.     'If user clicks the No button, stop QueryUnload.
    15.     If MsgBox(Msg, vbQuestion + vbYesNo, Me.Caption) = vbYes Then
    16.         objConn.Execute ("Delete from Documents where n_id = '" & objRs!n_id & "'")
    17.         MsgBox (objRs!n_pdfname)
    18.         MsgBox ("App.Path & "\" & "Documents" & "\" & '" & objRs!n_pdfname & "'")
    19.         'Kill  "App.Path & "\" & "Documents" & "\" & '" & objRs!n_pdfname & "'")
    20.     End If
    21.     objRs.Close
    22.     Call CloseConnection(objConn)
    He who never made a mistake never made a discovery?

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

    Re: need help with deleting file from folder

    If the path isn't correct, how about using a CommonDialog control and allowing the user to navigate to the file, select it, and then you can delete it.

  3. #3

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: need help with deleting file from folder

    Becuase I am already using a flex grid control to delete the name from the db. So I would like to delete the actual file as seamlessly as I am in the db.

    VB Code:
    1. Private Sub MSFlexGrid1_Click()
    2.  
    3.     Call CreateConnection(objConn)
    4.  
    5.     MSFlexGrid1.Col = 1    'identifies what column objRs.Source is below, the first col=0
    6.  
    7.     If Len(MSFlexGrid1.Text) <= 0 Then
    8.         Call CloseConnection(objConn)
    9.         Exit Sub
    10.     End If
    11.     '--------------------------------------------------
    12.     Call CreateConnection(objConn)
    13.  
    14.     Set objRs = New ADODB.Recordset
    15.  
    16.     objRs.ActiveConnection = objConn
    17.     objRs.CursorLocation = adUseClient
    18.     objRs.CursorType = adOpenDynamic
    19.     objRs.LockType = adLockOptimistic
    20.     objRs.Source = "select * from Documents where n_id='" & MSFlexGrid1.Text & "'"
    21.     objRs.Open
    22.  
    23.     Dim Msg
    24.     Msg = "Do you really want to delete this Document?"
    25.     'If user clicks the No button, stop QueryUnload.
    26.     If MsgBox(Msg, vbQuestion + vbYesNo, Me.Caption) = vbYes Then
    27.         objConn.Execute ("Delete from Documents where n_id = '" & objRs!n_id & "'")
    28.         MsgBox (objRs!n_pdfname)
    29.        MsgBox ("App.Path & "\" & "Documents" & "\" & '" & objRs!n_pdfname & "'")
    30.         'Kill  "App.Path & "\" & "Documents" & "\" & " & objRs!n_pdfname & "
    31.     End If
    32.     objRs.Close
    33.     Call CloseConnection(objConn)
    34.  
    35.     'THIS RESETS THE GRID - EFFECTIVELY REFRESHING
    36.     frmDeleteDocuments.MSFlexGrid1.Row = 0
    37.     Call dloadBios
    38.  
    39. End Sub
    He who never made a mistake never made a discovery?

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

    Re: need help with deleting file from folder

    Ok, but you said in your first post, "the path isn't correct"...see that you are selecting something from a flexgrid and trying to match it to a database record, I figured one of the has got to be wrong, but I don't know which one.

    What is in your DB table?
    What is displayed in your flexgrid?

  5. #5

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: need help with deleting file from folder

    Well it seemed to me that the path was incorrect, thats why I said that The db table consist of the id,a document name assigned by the user and the document's actual file name. Do I need to add the n_pdfname to the ADDitem string?

    Code:
    n_ident	n_id	n_name	n_pdfname
    77	17584	MS Word Document test	Westfield Script.doc
    The document n_name and n_id are displayed in the flex grid.
    I populate the flex grid this way;
    VB Code:
    1. Public Sub dloadBios()
    2.  
    3.     Call CreateConnection(objConn)
    4.  
    5.     MSFlexGrid1.Clear
    6.     MSFlexGrid1.FormatString = " Document Name |n_id"
    7.     'set colWidth before populating fields
    8.     MSFlexGrid1.ColWidth(0) = 4700    'first column p_name
    9.     MSFlexGrid1.ColWidth(1) = 1500    'third column p_id
    10.  
    11.     MSFlexGrid1.Rows = 1
    12.  
    13.     Set objRs = New ADODB.Recordset
    14.  
    15.     objRs.ActiveConnection = objConn
    16.     objRs.CursorLocation = adUseClient
    17.     objRs.CursorType = adOpenDynamic
    18.     objRs.LockType = adLockOptimistic
    19.     objRs.Source = "select * from Documents ORDER BY Documents.n_name;"
    20.     objRs.Open
    21.  
    22.     While Not objRs.EOF()
    23.         'ADDING RECORDS TO FLEXGRID
    24.         MSFlexGrid1.AddItem objRs!n_name & Chr(9) _
    25.                             & objRs!n_id & Chr(9)
    26.  
    27.         objRs.MoveNext
    28.  
    29.     Wend
    30.  
    31.     Set objRs = Nothing
    32.  
    33.     Call CloseConnection(objConn)
    34.  
    35. End Sub
    He who never made a mistake never made a discovery?

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

    Re: need help with deleting file from folder

    I think adding the actual path to your DB table would simplify things alot, yes.

    That way, you could also display the whole nine yards in your flexgrid.

  7. #7

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: need help with deleting file from folder

    Ok, I got it. I was putting the App.Path in quotes as well as the objRs!n_pdfname.

    VB Code:
    1. Kill App.Path & "\" & "Documents" & "\" & objRs!n_pdfname
    He who never made a mistake never made a discovery?

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