Solved

Creating a File from Command_click

Posted on 2000-05-12
2
123 Views
Last Modified: 2012-05-04
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.
0
Comment
Question by:R_N_WARD
  • 2
2 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 100 total points
Comment Utility
Private Sub CmdFile_Click()
   Dim exists As Boolean
   Dim filesys As Object
   Set filesys = CreateObject("Scripting.FileSystemObject")
   exists = filesys.FileExists("a:\dat1.dat")
   If exists Then
      MsgBox "File Exists Already"
   Else
      filesys.CreateTextFile("a:\dat1.dat")
   End If
End Sub
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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


0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now