Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to change the Caption with VBA

13 views
Skip to first unread message

Simon

unread,
Feb 11, 2007, 4:30:12 AM2/11/07
to
Dear reader,

I am familiar with the possibility to change the Caption of a field in a
form.

But is there also a possibility to change the Caption of a field in the
table structure it self.

I fount the following code to see the content of the Caption:

Debug.Print
CurrentDb.TableDefs("TableName").Fields("FieldName").Properties("caption")

But now the code to change the Caption.

Tanks for any help.

Kind regards,

Simon


Allen Browne

unread,
Feb 11, 2007, 5:32:02 AM2/11/07
to
Simon, if the Caption has never been set, then the property doesn't exist,
so you need to CreateProperty. If it does exist, you just need to assign the
value.

The code below creates the property if needed, or sets it if it already
exists. Example:
Call SetProperty(Currentdb.TableDefs("TableName").Fields("FieldName"),
"Caption", dbText, "My caption")


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

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Simon" <SvanB...@Versatel.nl> wrote in message
news:45cee20d$0$6315$bf49...@news.tele2.nl...

0 new messages