descriptions on table

N

Nuno Guerra

I usually import some tables from other sources to access.
I have to put some description for each import I made, but I have been made
this manually.

Is there a way to make this using code?

Thanks.
 
A

Allen Browne

Use the code below like this:
? SetPropertyDAO(CurrentDb.TableDefs("Table1", dbText, "I imported
this!")

Function SetPropertyDAO(obj As Object, strPropertyName As String, intType As
Integer, varValue As Variant, Optional strErrMsg As String) As Boolean
On Error GoTo ErrHandler
'Purpose: Set a property for an object, creating if necessary.
'Arguments: obj = the object whose property should be set.
' strPropertyName = the name of the property to set.
' intType = the type of property (needed for creating)
' varValue = the value to set this property to.
' strErrMsg = string to append any error message to.

If HasProperty(obj, strPropertyName) Then
obj.Properties(strPropertyName) = varValue
Else
obj.Properties.Append obj.CreateProperty(strPropertyName, intType,
varValue)
End If
SetPropertyDAO = True

ExitHandler:
Exit Function

ErrHandler:
strErrMsg = strErrMsg & obj.Name & "." & strPropertyName & " not set to
" & varValue & ". Error " & Err.Number & " - " & Err.Description & vbCrLf
Resume ExitHandler
End Function

Public Function HasProperty(obj As Object, strPropName As String) As Boolean
'Purpose: Return true if the object has the property.
Dim varDummy As Variant

On Error Resume Next
varDummy = obj.Properties(strPropName)
HasProperty = (Err.Number = 0)
End Function
 
N

Nuno Guerra

I create a new form just to test it:

Private Sub Command0_Click()
SetPropertyDAO (CurrentDb.TableDefs("Table1", dbText, "I imported this!"))
End Sub

when I debug, I had this error:
"Compile error:
Wrogn number of arguments or invalid propert assigment"
on
".TableDefs"

can you help me?
 
A

Allen Browne

Hmm. There was a bracket missing in the example.

Spell it out like this:
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Set db = CurrentDb()
Set tdf = db.TableDefs("Table1")
Call SetPropertyDAO (tdf, "Description", dbText, "Whatever")
 
N

Nuno Guerra

Thanks Allen, it works!!!
I also went to your web site about DAO Object Model, and it becames very
helpfull.

thanks again.
NG
 
Top