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:
Call CreateConnection(objConn)
Set objRs = New ADODB.Recordset
objRs.ActiveConnection = objConn
objRs.CursorLocation = adUseClient
objRs.CursorType = adOpenDynamic
objRs.LockType = adLockOptimistic
objRs.Source = "select * from Documents where n_id='" & MSFlexGrid1.Text & "'"
objRs.Open
Dim Msg
Msg = "Do you really want to delete this Document?"
'If user clicks the No button, stop QueryUnload.
If MsgBox(Msg, vbQuestion + vbYesNo, Me.Caption) = vbYes Then
objConn.Execute ("Delete from Documents where n_id = '" & objRs!n_id & "'")
MsgBox (objRs!n_pdfname)
MsgBox ("App.Path & "\" & "Documents" & "\" & '" & objRs!n_pdfname & "'")
'Kill "App.Path & "\" & "Documents" & "\" & '" & objRs!n_pdfname & "'")
End If
objRs.Close
Call CloseConnection(objConn)
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.
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:
Private Sub MSFlexGrid1_Click()
Call CreateConnection(objConn)
MSFlexGrid1.Col = 1 'identifies what column objRs.Source is below, the first col=0
If Len(MSFlexGrid1.Text) <= 0 Then
Call CloseConnection(objConn)
Exit Sub
End If
'--------------------------------------------------
Call CreateConnection(objConn)
Set objRs = New ADODB.Recordset
objRs.ActiveConnection = objConn
objRs.CursorLocation = adUseClient
objRs.CursorType = adOpenDynamic
objRs.LockType = adLockOptimistic
objRs.Source = "select * from Documents where n_id='" & MSFlexGrid1.Text & "'"
objRs.Open
Dim Msg
Msg = "Do you really want to delete this Document?"
'If user clicks the No button, stop QueryUnload.
If MsgBox(Msg, vbQuestion + vbYesNo, Me.Caption) = vbYes Then
objConn.Execute ("Delete from Documents where n_id = '" & objRs!n_id & "'")
MsgBox (objRs!n_pdfname)
MsgBox ("App.Path & "\" & "Documents" & "\" & '" & objRs!n_pdfname & "'")
'Kill "App.Path & "\" & "Documents" & "\" & " & objRs!n_pdfname & "
End If
objRs.Close
Call CloseConnection(objConn)
'THIS RESETS THE GRID - EFFECTIVELY REFRESHING
frmDeleteDocuments.MSFlexGrid1.Row = 0
Call dloadBios
End Sub
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?
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:
Public Sub dloadBios()
Call CreateConnection(objConn)
MSFlexGrid1.Clear
MSFlexGrid1.FormatString = " Document Name |n_id"
'set colWidth before populating fields
MSFlexGrid1.ColWidth(0) = 4700 'first column p_name
MSFlexGrid1.ColWidth(1) = 1500 'third column p_id
MSFlexGrid1.Rows = 1
Set objRs = New ADODB.Recordset
objRs.ActiveConnection = objConn
objRs.CursorLocation = adUseClient
objRs.CursorType = adOpenDynamic
objRs.LockType = adLockOptimistic
objRs.Source = "select * from Documents ORDER BY Documents.n_name;"
objRs.Open
While Not objRs.EOF()
'ADDING RECORDS TO FLEXGRID
MSFlexGrid1.AddItem objRs!n_name & Chr(9) _
& objRs!n_id & Chr(9)
objRs.MoveNext
Wend
Set objRs = Nothing
Call CloseConnection(objConn)
End Sub
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.
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:
Kill App.Path & "\" & "Documents" & "\" & objRs!n_pdfname