Consulting

Results 1 to 6 of 6

Thread: Rename a Document by textbox value via VBA

  1. #1

    Post Rename a Document by textbox value via VBA

    Hello everyone, What I am trying to accomplish is rename a document from textbox value, both file source path and destination path are stored in two separate textboxes called Text50 and Text59, I do understand the Name function, but it seems only works if I spell out the full path, can I use my textbox as a variable in VBA?


    Thanks a lot for the help

  2. #2
    Yes, you can reference your textbox's from VBA code.

    First, I highly recommend changing the default names used form control s to something more meaningful. Especially if you are going to reference them in code.

    Example:
    Text50 would renamed to txtDirectoryPath
    Text59 would be renamed to txtFileName



    If the code is behind the form (in the form's code module) you can use:

    Example
    Dim strFullPath As String 
     
    strFullPath  = Me.txtDirectoryPath & "\" & Me.txtFileName 
    
    
    Formatting tags added by mark007
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  3. #3
    Hello HiTechCoach,
    Thanks for the reply, and the suggestion.
    I renamed two textboxes to sourFullPath and destFullPath (both textbox already include the whole path of the file and the file name together) So here is my code:
    Dim strFullPathSour As String 
    Dim strFullPathDest As String 
    strFullPathSour = Me.sourFullPath 
    strFullPathDest = Me.destFullPath 
    Name strFullPathSour As strFullPathDest 
    
    
    Formatting tags added by mark007
    But it gives me Run-time error '5', Invalid procedure call or argument
    Do you have any suggestion for what causes that.

    Thanks

  4. #4
    TIP: No need to dim the variables and assign the variables.

    You can use:

    Name Me.sourFullPath As Me.destFullPath 
    
    
    Formatting tags added by mark007

    Name only can change folders on the same drive.



    Is the destination folder on the same drive?
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  5. #5
    Quote Originally Posted by HiTechCoach View Post
    TIP: No need to dim the variables and assign the variables.

    You can use:

    Name Me.sourFullPath As Me.destFullPath 
    
    
    Formatting tags added by mark007

    Name only can change folders on the same drive.



    Is the destination folder on the same drive?
    Yes they are on the same drive.

  6. #6
    Here are some potential issues to consider:

    Does the destination folder already exist?

    Are you attempting to over-write an existing file in the destination folder?

    Is the source file opened in another application?

    Doe you have any objects (a control or field in the record source) on the form with the name "Name"?
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

Tags for this Thread

Posting Permissions

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