Results 1 to 9 of 9
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    rename object


    All, using access 2010. I have some code to rename a table in my database. Partial Code:
    Code:
    TableDefs("tblMstr").Name = "tblMstr" & Format(Date, "yyyymmdd")
    This works fine. But is there a way possible for code to look at the tbl properties of when it was created to use this date? I really need it to be dated so I know what date of the data was taken. Just a thought.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Here is a list of the TableDef members.
    http://msdn.microsoft.com/EN-US/libr...ffice.15).aspx

    Perhaps you can get the info needed using the LastUpdated property
    http://msdn.microsoft.com/EN-US/libr...ffice.15).aspx

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    I tried to us DateCreated but keep getting errors such as variable not defined or .datecreated without a with block. How do I format the date using DateCreated?

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by slimjen View Post
    ... .datecreated without a with block...
    Post your code. It seems as though your are not instantiating your object and or using the correct syntax for the method.

  5. #5
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Ok: Here it is. It works without the DateCreated as expected.

    Code:
    Dim dbBackend As DAO.Database
    Dim strBackendDatabase As String
      strBackendDatabase = "c:\TestFolder\Sampledb.accdb"
      Set dbBackend = OpenDatabase(strBackendDatabase)
    dbBackend. TableDefs("tblMstr").Name = "tblMstr" & Format(Date,  &  DateCreated "yyyymmdd")
      dbBackend.Close
      Set dbBackend = Nothing
    Thanks

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe

    Format(dbBackend.TableDefs("tblMstr").DateCreated, "yyyymmdd")

  7. #7
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    This works fine. But is there a way possible for code to look at the tbl properties of when it was created to use this date? I really need it to be dated so I know what date of the data was taken. Just a thought.
    So, does this lead to multiple copies of similar tables in your database with different dates?
    If so, I am not certain that is the best design.

    I would probably try doing something like adding "Date" field to your table, and record the Date you want in each record.

  8. #8
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    I tried this gave errors. I know it's not the best design but it will surfice for what the users wants for now.

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Why don't you try splitting it up so you can see where it is not working

    Dim dtMade as date
    dim strName as string
    dtMade = dbBackend.TableDefs("tblMstr").DateCreated
    debug.print dtMade

    strName = "tblMstr" & Format(dtMade, "yyyymmdd")
    debug.print strName

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 07-02-2013, 08:41 AM
  2. Replies: 1
    Last Post: 09-03-2011, 07:01 PM
  3. rename ole object
    By rbg in forum Access
    Replies: 0
    Last Post: 11-29-2010, 03:13 AM
  4. Replies: 3
    Last Post: 11-02-2010, 10:14 AM
  5. Replies: 1
    Last Post: 08-05-2010, 12:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums