Setting Table Description property with code

G

Guest

Hello, I'm not a programmer, just a copy and paster ;), and I've found the
following code to help me copy a table as a backup, however it copies the
description as well and I don't want it to. In researching this site, I
found information that says I must set the DAO reference library(?). Is this
something I can do or will I need to call my sysadmin over to install
something?

So here's the code I'm using...what needs to be tweaked in order for me to
change the table description property? Thanks

Option Compare Database

Private Sub Command0_Click()
Dim dest As String

dest = "DCPDS Backup - EOM " & Format(Now - Day(Now), "mmm yy")
DoCmd.CopyObject , dest, acTable, "Current DCPDS"
End Sub

Sub SetDescription(TableName As String, _
TableDescription As String)

On Error GoTo Err_SetDescription

Dim tdfCurr As DAO.TableDef
Dim prpDesc As DAO.Property

Set tdfCurr = CurrentDb().TableDefs(TableName)
tdfCurr.Properties("Description") = TableDescription

End_SetDescription:
Exit Sub

Err_Property:
' Error 3270 means that the property was not found.
If Err.Number = 3270 Then
' Create property, set its value, and append it to the
' Properties collection.
Set prpDesc = tdfCurr.CreateProperty( _
"Description", dbText, TableDescription)
tdfCurr.Properties.Append prpNew
Resume Next
Else
MsgBox "Error " & Err.Number & " (" & _
Err.Description & ")"
Resume End_SetDescription
End If
End Sub
 
N

Nikos Yannacopoulos

Hi again Laura,

It's starting to make sense now. No, you don't need to call anybody.
While in the VBA window, go Tools > References; check if a Microsoft DAO
reference is present among the ones checked at the top of the list. If
not, scroll down to find the appropriate Microsoft DAO X.X Object
Library reference and check it. The appropriate reference is DAO 3.51
for A97, DAO 3.6 for A2K or later.

HTH,
Nikos
 
N

Nikos Yannacopoulos

Laura,

Here it is:

Sub SetDescription(TableName As String, _
TableDescription As String)
Dim dbs As Database, ctr As Container, doc As Document
Dim strTabChar As String
Set dbs = CurrentDb
strTabChar = vbTab
Set ctr = dbs.Containers("Tables")
Set doc = ctr.Documents(TableName)
doc.Properties("Description") = TableDescription
End Sub

HTH,
Nikos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top