Hi Everyone,

I have two buttons that I want only 1, the problem I have is the first button overrides any files with the same name, I want it to check if exists then action 2nd button.

I know it is bad code, any way to simplify would be great

Thanks Heaps

Code below

Private Sub CreateFilenote_Click()
' create filenote button
Dim fso, MyFile, strName, strBranch, WSName, CName, strFile, strInput, strExt
Dim YesOrNoAnswerToMessageBox As String
Dim QuestionToMessageBox As String

QuestionToMessageBox = "Have you created a Filenote before"

YesOrNoAnswerToMessageBox = MsgBox(QuestionToMessageBox, vbYesNo, "Create New Filenote")

If YesOrNoAnswerToMessageBox = vbYes Then
MsgBox "Please edit the original file!"
Else
WSName = "Tracker"
CName = "C1"
strBranch = Sheets(WSName).Range(CName).Text
strFile = "G:\" & strBranch & "\name\Filenotes\"
strName = InputBox("Enter Applicants SURNAME:" & vbCrLf & vbCrLf & "Please enter SURNAME in capitals", _
"Create File")
strExt = ".doc"
strInput = (strFile & strName & strExt)
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile(strInput, True)
MyFile.WriteLine ("")
MyFile.Close
MsgBox "Filenote for " & strName & " Created "

Exit Sub
End If

Private Sub AddFilenote_Click()
' add filenote button
Dim fso, f, ReadAllTextFile, strFile, strName, strExt, strInput, strNotes, strBranch, WSName, CName
WSName = "Tracker"
CName = "C1"
strBranch = Sheets(WSName).Range(CName).Text
strFile = "G:\" & strBranch & "\name\Filenotes\"
strName = InputBox("Enter Applicants SURNAME:", _
"Create File")
strExt = ".doc"
strInput = (strFile & strName & strExt)
filenote.Show
strNotes = filenote.TextBox1
Set strNotes = filenote.TextBox1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(strInput, 1)
ReadAllTextFile = f.ReadAll
Set f = fso.OpenTextFile(strInput, 2, True)
f.WriteLine (Date & "," & vbCrLf & strNotes)
f.Write (ReadAllTextFile)

MsgBox "Filenote Added - Thanks"


End Sub