Question : Ask user if they wish to overwrite existing file

Hi,

I have the following code on a cmd button which saves a document into my database.  The AhEmptyName: section lets the user enter a new name for the document if a document with the same name is already in the directory.  Although this works ok, i would like the user to have the option to either overwrite the existing document or choose a new name.  Similar to the save function in other programs when it finds a file with the same name.

Any clues?  Do i just include a kill method to remove the exisitng file and then continue witht the rest of the code?

Thanks,
Tom
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
Private Sub cmdAttach_Click()
'On Error GoTo errline
    
    Dim db As dao.Database
    Dim rs As dao.Recordset
    Dim LastSlash As Integer
    Dim fname As String
    Dim DestinationPathAndName As String
    Dim strFolder As String
    
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tbl_documents", dbOpenDynaset, dbSeeChanges, dbOptimistic)
    
    If Not IsNull(Me.document_path) Or Not IsNull(Me.file_type) Then
    
     LastSlash = InStrRev(Me.document_path, "\")  'the location of the last slash before the file name
     fname = Mid(Me.document_path, LastSlash + 1) 'the file name without path
     
     DestinationPathAndName = GBLnetworkStoragePath & "\" & "documents"
     If Len(Dir(GBLnetworkStoragePath & "\" & "documents", vbDirectory)) > 0 Then
    'Directory Exists
Else
    'Create the folder
    MkDir GBLnetworkStoragePath & "\" & "documents"
End If
         
 
CheckAgain:
'check if the file name exists, before copying the new file
If Dir(DestinationPathAndName & "\" & fname) <> "" Then
   'the exists, so let's ask the user to
AhEmptyName:
    fname = InputBox("Please enter a new file name.  You must include the file extension.")
    If Len(Trim(fname)) = 0 Then
    MsgBox "Please enter a file name"
    GoTo AhEmptyName
End If

   'let's check again on the new file name existance
   GoTo CheckAgain
Else
   'does not exists, so let the code flow to continue
End If
 
 
     FileCopy Me.document_path, DestinationPathAndName & "\" & fname 'copy the file to the new destination
   
        rs.AddNew
        rs("document_desc") = Me.document_desc
        rs("company_id") = Me.company_id
        rs("file_type") = Me.file_type
        rs("attachment") = Me.chkAttachment
        rs("document_path") = DestinationPathAndName & "\" & fname   'assign the new location to the Table

        rs.Update
    Else
        MsgBox "You need to browse for a document and select a file type.", vbCritical, "Error"
        Me.document_desc.SetFocus
    End If
    rs.Close
    db.Close
    MsgBox "Document has been saved to this company contact.", vbInformation, "Attach Document"
    
    Set rs = Nothing
    Set db = Nothing
    DoCmd.Close


exitline:
  Exit Sub
     
errline:
Select Case Err.Number
Case 94
MsgBox "There are blank fields", vbExclamation, "Error..."
Case 2450
MsgBox "ContactPLUS needs to restart", vbExclamation, "Error..."
Call Restart
Case Else
MsgBox "An error has occured.  Please notify the Database Administrator of the following error number:" & Err.Number & vbCrLf & "The error message is: " & Err.Description
GoTo exitline
End Select
End Sub

Answer : Ask user if they wish to overwrite existing file

Hi again,

did you actually run "cfgmgr -v fcs0" ?

Because this is a syntax error (the correct format would have been "cfgmgr -v -l fcs0")
it's no wonder that cfgmgr didn't do what you expected ... but you should have seen an error message!

The "-v" flag only means "verbose" and doesn't have any influence on cfgmgr's functionality!

Anyway, the "-l (name)" parameter instructs cfgmgr to configure the device (name) and all its children,
so with the above format you should at least have seen the fscsix0 children of fcsx, and with HDLM's configuration method the appropriate paths should be there, too.

"cfgmgr" alone (or with "-v") on the other hand would try to configure any device it finds.

So if you actually used "cfgmgr -v -l fcs0" without success it could be that Hitachi DLM would have some special method which is not triggered along with the fcsx configuration.

It's some years ago that our last HDS Lightning got scrapped, so I fear you will have to post the output of "lsdev -C" or even "lscfg" for me to check, if you'd like to dig deeper into this.


wmp
Random Solutions  
 
programming4us programming4us