Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 31st, 2007, 09:53 AM
Authorized User
 
Join Date: Oct 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creation date of a table

I am trying to figure out how to retrieve the creation date of a table using vba, so that it can be displayed in a form and a report.

 
Old November 2nd, 2007, 06:24 AM
Authorized User
 
Join Date: Oct 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The quickest way I can think of offhand is to grab it from the MSysObjects table, which is one of the
several system tables in an MSAccess MDB database file. Here's an example:

Dim TableCreateDtTm As Date
Dim TableName As String
Dim WhereCond As String

TableName = "MyTable"
WhereCond = "Name = '" & TableName '" & And Type = 1"

TableCreateDtTm = DLookup("DateCreate", "MSysObjects", WhereCond)

MSysObjects contains a bunch of information for all objects in an MS Access MDB database file. You
can see all existing system tables for an MDB by selecting Tools | Options, selecting the View tab,
and clicking 'System Tables' to TRUE.

Each object type has its own number assigned to it - here's the most common ones:

Table (Native: non-linked) = 1
Table (ODBC-linked) = 4
Table (MS Jet/Access linked) = 6
Query = 5
Form = -32768
Report = -32764
Macro = -32766
Module = -32761

Please note that when using this method, the actual date create coming from MSysObjects will
be accurate for Native (non-linked) tables only. The information for the Create Date for a
linked table will be stored in either the other MDB database (MS Jet-linked) or in a system
table, etc for an ODBC-linked table.

Hope that helps!

Warren

:)
 
Old November 2nd, 2007, 08:08 AM
Authorized User
 
Join Date: Oct 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried this but got an error message of Syntax error in string in query expression 'Name = 'Shippers Report'.

The name of the table i am trying to get the date from is "Shippers Report"

The code i am using is below

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

    Dim TableCreationDtTm As Date
    Dim TableName As String
    Dim WhereCond As String

    TableName = "Shippers Report"
    WhereCond = "Name = '" & TableName '" & And Type = 1"

    TableCreationDtTm = DLookup("DateCreate", "MSysObjects", WhereCond)

    Me![txtDate] = TableCreationDtTm

Exit_Form_Open:
    Exit Sub

Err_Form_Open:
    MsgBox Err.Description
    Resume Exit_Form_Open

End Sub
 
Old November 2nd, 2007, 09:20 AM
Authorized User
 
Join Date: Oct 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My apologies - should have tried running the code myself first.

Old: WhereCond = "Name = '" & TableName '" & And Type = 1"

New: WhereCond = "Name = '" & TableName & "' And Type = 1"
 
Old November 2nd, 2007, 10:52 AM
Authorized User
 
Join Date: Oct 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks its working fine now.

:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Table creation sunny227 XSLT 3 November 14th, 2007 02:50 PM
Regarding Table of Contents Creation forrestfsu XSLT 7 June 21st, 2007 03:04 PM
creation of table from xml file s2_saha XML 0 April 27th, 2007 01:14 AM
Get file creation date shamsad Oracle 0 February 6th, 2004 06:59 AM
Table Creation rgerald Access VBA 1 June 24th, 2003 08:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.