Consulting

Results 1 to 4 of 4

Thread: Solved: Run Time Error '76'

  1. #1
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location

    Solved: Run Time Error '76'

    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:

    [VBA]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
    Else
    MsgBox "You do not have sufficient privileges!"
    Unload Me
    End If
    End Sub[/VBA]

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

    I am attaching herewith, the Excel file. Awaiting your kind feedback.
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  2. #2
    VBAX Contributor
    Joined
    May 2010
    Location
    Sydney, NSW, Australia
    Posts
    170
    Location
    Shouldn't you be using name for renaming a file?
    [vba]
    Name OldName as NewName
    [/vba]

    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.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    The problem is being caused because you have the / character in date, and that is invalid in a filename. Try

    [vba]

    NewName = Left(OldName, 70) & "_" & Format(Date, "yyyy-mm-dd") & ".txt"
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    @ 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.
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •