View Full Version : Solved: Run Time Error '76'

08-26-2010, 08:40 PM
Been many days since I visited the forum let alone troll. Its been great help for me. Ok, here goes my query.

I am working on building an Excel Sheet which imports *.txt, *.RES files for a colleague in another department. He wanted the program to have a control (fixed number of attempts) but then being the myopic guy I am I did not consider the renewal option. To achieve that I created a userform to provide username and password. And here the problems began with the code below:

Private Sub PassWord_AfterUpdate()
Dim OldName, NewName As String
Dim FSO As Object
OldName = "C:\Documents and Settings\All Users\Application Data\FlareLog\UsageLog.txt"
NewName = Left(OldName, 70) & "_" & Date & ".txt"
If LogIn.Value = "Admin" And PassWord.Value = "Sachin" Then
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.MoveFile OldName, NewName
Set FSO = Nothing
MsgBox "Subscription Renewed!"
Unload Me
MsgBox "You do not have sufficient privileges!"
Unload Me
End If
End Sub

The error comes specifically at FSO.MoveFile OldName, NewName.

I am attaching herewith, the Excel file. Awaiting your kind feedback.

Blade Hunter
08-26-2010, 10:01 PM
Shouldn't you be using name for renaming a file?

Name OldName as NewName

Seems strange to me that you would use the file move function to rename a file.

Also means you don't need to use the filesystem object at all.

08-27-2010, 12:13 AM
The problem is being caused because you have the / character in date, and that is invalid in a filename. Try

NewName = Left(OldName, 70) & "_" & Format(Date, "yyyy-mm-dd") & ".txt"

08-27-2010, 07:31 AM
@ Blade Hunter: I forgot to mention @ the try with Name but it gave me another Run time (53 or 55) file not found. It was first choice as it does not involve declaring object. Since it failed me I tried this. In fact, OldName and NewName are the remnants of the ole' code :)

Looks to me as if XLD's suggestion is the reason.

Thank you both for your kind inputs. I will be back with the results tomorrow.