A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Changing Field Captions in VBA



 
 
Thread Tools Display Modes
  #1  
Old July 13th, 2004, 04:10 PM
Dave Johnson
external usenet poster
 
Posts: n/a
Default Changing Field Captions in VBA

Anyone Know how to Change Table field captions using VBA
code.
  #2  
Old July 13th, 2004, 04:36 PM
Duane Hookom
external usenet poster
 
Posts: n/a
Default Changing Field Captions in VBA

I am not sure why you want to apply captions to fields. It's generally
agreed that users should be prevented from viewing any records in tables.
Forms allow you to set any label captions that you want. When I (as a
developer) view a table or query, I want to see the REAL field names, not
some captions.

I handle captions, input masks, format, and lookup field properties in
tables all the same... ignore them.

--
Duane Hookom
MS Access MVP
--

"Dave Johnson" wrote in message
...
Anyone Know how to Change Table field captions using VBA
code.



  #3  
Old July 13th, 2004, 05:05 PM
Allen Browne
external usenet poster
 
Posts: n/a
Default Changing Field Captions in VBA

Set the Caption property of the Field in the TableDef.
If the property does not exist, you have to create it.

Call SetPropertyDAO(dbEngine(0)(0).TableDefs("Table1"). Fields("Field1"),
"Caption", dbText, "Whatever you want as the caption here.")


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.

"Dave Johnson" wrote in message
...
Anyone Know how to Change Table field captions using VBA
code.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 97 - Changing field back colors in reports Pete Sperling Setting Up & Running Reports 6 July 6th, 2004 03:04 PM
NUMBERING the pages Bob New Users 7 June 14th, 2004 12:20 AM
Changing field indexed property from code Christopher Database Design 0 June 11th, 2004 03:17 PM
Format of captions lost when toggle field marcustockstall Formatting Long Documents 1 May 29th, 2004 03:00 AM


All times are GMT +1. The time now is 08:29 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.