Syntax for appending a table property

T

Terry

What is the correct syntax for creating and appending a new property to a
table? I need to create the property "SubDataSheetName" and give it a value.
Regards
 
A

Allen Browne

Function TurnOffSubDataSh()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim prp As DAO.Property
Const conPropName = "SubdatasheetName"
Const conPropValue = "[None]"

Set db = DBEngine(0)(0)
For Each tdf In db.TableDefs
If (tdf.Attributes And dbSystemObject) = 0 Then
If tdf.Connect = vbNullString And Asc(tdf.Name) <> 126 Then 'Not
attached, or temp.
If NoSuchProperty(tdf, conPropName) Then
Set prp = tdf.CreateProperty(conPropName, dbText,
conPropValue)
tdf.Properties.Append prp
Else
If tdf.Properties(conPropName) <> conPropValue Then
tdf.Properties(conPropName) = conPropValue
End If
End If
End If
End If
Next
Set db = Nothing
End Function

Private Function NoSuchProperty(obj As Object, strPropName As String) As
Boolean
Dim varDummy As Variant

On Error Resume Next
varDummy = obj.Properties(strPropName)
NoSuchProperty = (Err.Number = 3270)
On Error GoTo 0
End Function
 
T

Terry

Thanks Allen,
I can now see where I was going wrong.
Regards
Terry

Allen Browne said:
Function TurnOffSubDataSh()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim prp As DAO.Property
Const conPropName = "SubdatasheetName"
Const conPropValue = "[None]"

Set db = DBEngine(0)(0)
For Each tdf In db.TableDefs
If (tdf.Attributes And dbSystemObject) = 0 Then
If tdf.Connect = vbNullString And Asc(tdf.Name) <> 126 Then 'Not
attached, or temp.
If NoSuchProperty(tdf, conPropName) Then
Set prp = tdf.CreateProperty(conPropName, dbText,
conPropValue)
tdf.Properties.Append prp
Else
If tdf.Properties(conPropName) <> conPropValue Then
tdf.Properties(conPropName) = conPropValue
End If
End If
End If
End If
Next
Set db = Nothing
End Function

Private Function NoSuchProperty(obj As Object, strPropName As String) As
Boolean
Dim varDummy As Variant

On Error Resume Next
varDummy = obj.Properties(strPropName)
NoSuchProperty = (Err.Number = 3270)
On Error GoTo 0
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.


Terry said:
What is the correct syntax for creating and appending a new property to a
table? I need to create the property "SubDataSheetName" and give it a value.
Regards
 

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