Link to home
Start Free TrialLog in
Avatar of R_N_WARD
R_N_WARD

asked on

Creating a File from Command_click

I want the computer to create a file (namely A:\DAT1.DAT) when the user presses CmdFile_click. I also want code that will find if that file is already on the disk and ask the user if they wish to replace it.
ASKER CERTIFIED SOLUTION
Avatar of AzraSound
AzraSound
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
a more complete example:

Private Sub CmdFile_Click()
    Dim exists As Boolean
    Dim i As Integer
    Dim filesys As Object
    Set filesys = CreateObject("Scripting.FileSystemObject")
    exists = filesys.FileExists("c:\windows\desktop\dat1.dat")
    If exists Then
        i = MsgBox("File Exists Already.  Do you wish to overwrite it?", _
            vbYesNo)
        If i = vbYes Then _
            filesys.CreateTextFile "c:\windows\desktop\dat1.dat", True
    Else
        filesys.CreateTextFile ("c:\windows\desktop\dat1.dat")
   End If
End Sub