Solved

Creating a File from Command_click

Posted on 2000-05-12
2
137 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 100 total points
ID: 2805371
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
ID: 2805394
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

717 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