Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / October 2007

Tip: Looking for answers? Try searching our database.

Editing Caption Property

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob Darlington - 26 Oct 2007 08:10 GMT
I'm using the following code to try to change a caption property for a field
in a table.
   Dim dbs As Database, fld As Field, fFormat As Property
   Set dbs = OpenDatabase(CurrentDataFile)
   Set fld = dbs.TableDefs(tblName).Fields(fldName)
   Set fFormat = fld.CreateProperty("Caption", dbText, strCaption)
   fld.Properties.Append fFormat

Each time it's generating error 3367 - "Cannot Append. An object with that
name already exists".
It doesn't matter what strCaption I enter, the same message appears.
I'm using Access 2002.
Any ideas welcome.

Signature

Bob Darlington
Brisbane

Stuart McCall - 26 Oct 2007 08:53 GMT
> I'm using the following code to try to change a caption property for a
> field in a table.
[quoted text clipped - 9 lines]
> I'm using Access 2002.
> Any ideas welcome.

This function first tries to set an already existing property, and if an
error 3270 (property not found) occurs, it appends the new property to the
collection. Paste it into a standard module:

''' BEGIN CODE '''
Sub SetObjProperty(pObject As Object, pProperty As String, pType As Integer,
pValue As Variant)
   Const PROPERTY_NOT_FOUND As Long = 3270
   Dim prp As Property
   '
   On Error GoTo SetObjProperty_Err
   '
   pObject.Properties(pProperty) = pValue
   pObject.Properties.Refresh

SetObjProperty_Exit:
   Set prp = Nothing
   Exit Sub

SetObjProperty_Err:
   If Err.Number = PROPERTY_NOT_FOUND Then
       With pObject
           Set prp = .CreateProperty(pProperty, pType, pValue)
           .Properties.Append prp
           .Properties.Refresh
       End With
       Resume SetObjProperty_Exit
   Else
       MsgBox Err.Number & ": " & Err.Description, vbCritical,
"SetObjProperty"
       Resume SetObjProperty_Exit
   End If

End Sub
''' END CODE '''

Use it like this:

SetObjProperty fld, "Caption", dbText, strCaption
Bob Darlington - 30 Oct 2007 06:32 GMT
Thanks Stuart,
Sorry about the delay getting back to you.

Signature

Bob Darlington
Brisbane

>> I'm using the following code to try to change a caption property for a
>> field in a table.
[quoted text clipped - 49 lines]
>
> SetObjProperty fld, "Caption", dbText, strCaption
Keith Wilby - 26 Oct 2007 09:32 GMT
> I'm using the following code to try to change a caption property for a
> field in a table.
[quoted text clipped - 9 lines]
> I'm using Access 2002.
> Any ideas welcome.

Hi Bob.

Just a shot in the dark but wouldn't the property you're trying to create
already exist?  Shouldn't you be trying to set its value rather than create
it?

Keith.
www.keithwilby.com
Bob Darlington - 30 Oct 2007 06:33 GMT
Thanks Keith,
That was it (see Stuart's reply).
Sorry about the delay getting back to you.

Signature

Bob Darlington
Brisbane

>> I'm using the following code to try to change a caption property for a
>> field in a table.
[quoted text clipped - 18 lines]
> Keith.
> www.keithwilby.com
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.