Consulting

Results 1 to 5 of 5

Thread: Application Object In Access

  1. #1

    Application Object In Access

    I have a routine that I run in the On Open event in Excel. It creates a backup of the file with the came name, directory, etc. but as a Date and Time to the file name. This is a very handy way "for me" to recovery from my self imposed disasters, I am supposed to put the code in the text area. I am not sure where that is. Not finding that I will carefully submit my current Subroutine, The issue that I am having is with With.ThisWorkBook and Application.WorksheetFunction. What are the corresponding values for Access. I have found where to put the code, I now just need to know what code to put there.

    Please explain what I need to do to get to the Text Area or whatever,
    here is the code:
    ==========================
    Private Sub Workbook_Open()
    Dim sFileName As String
    Dim sDateTime As String


    With ThisWorkbook
    sDateTime = " (" & Format(Now, "yyyy-mm-dd hhmm") & ").xlsm"
    sFileName = Application.WorksheetFunction.Substitute _
    (.FullName, ".xlsm", sDateTime)
    .SaveCopyAs sFileName
    End With
    End Sub
    ==========================
    Thank you for any help you might provide and also "tell me where to go" on the Text Area feature.
    DannyDont

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    I have this code, which was generated many years ago by a great poster on here.
    The "saving" part of the code is in a subroutine, but could be in a Module, which can be called from VBA or from an Autoexec Macro.

    Sub Backsup() 
        Dim SourceFile, DestinationFile 
        SourceFile = "C:\Data\MyData.mdb" ' Define source file name.
         ' Define target file name.
        DestinationFile = "C:\Data\" & Format(Now(), "dddd") & "\MyData.mdb" 
        FileCopy SourceFile, DestinationFile ' Copy source to target.
    End Sub

  3. #3
    Lost in a Forum OUCH! - I have not done forums before. Do I use the Reply in your message slot or do I use the Reply to Thread? My thinking is that the Reply in your message will get the message only to you. If I use the Reply to this Thread, it will be seen by anyone/everyone. I am not sure what proper protocol is. Can you help with that. (Since I used the Reply in your message, I am hoping this is going only to you.

    Regardless, I than you for your help. I will test that out "soon". I sort of need this as I shot myself in the foot the other day and had to rewrite a bunch of VBA code in my Access app. My attempt here is rather like closing the barn door after the horse has gotten out!

  4. #4
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Either way you reply will display on the forum.
    Anybody transferring from Excel to Access will be lost for a while until they realise how Access is structured and the fact that although they share a lot of VBA they both have exclusive code, ie workbooks and sheets in Excel and forms and reports in Access, plus each object on the Access form can also be referred to as well.

  5. #5
    Oh, how I understand that statement. I have worked around the edges of Access for several years and am now on another project. I feel as though I am getting better. Practice makes perfect. One thing that I find difficult is how the Event code is sort of in no logical order. When I write VBA, I like to keep my subroutines in alpha order so I can find them easily. All the interrupts are confusing. I know about interrupts from previous years of work but just can't get my arms around that just yet. It will come. And like you say there all the objects that each have a label name, a field name and a field value. A lot to remember when you are coding.

    Thank for your comments.

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
  •