473,385 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to change the Caption with VBA

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
Feb 11 '07 #1
1 6848
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").Field s("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" <Sv********@Versatel.nlwrote in message
news:45**********************@news.tele2.nl...
>
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
Feb 11 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: SPG | last post by:
Hi, I wrote a little bit of script that loads an image from a thumbnail when the thumbnail is clicked. It is not very clever, and I have found it only works in IE.. could someone have a look...
3
by: Jigar Mehta | last post by:
Hye, I am Jigar Mehta, currently, I am using AfxMessageBox where I need to change the caption of the messagebox using that function only... What I get is, the project name as the caption. I don't...
3
by: spielmann | last post by:
Hello I want to change the scrollbar size of windows, How can I do that with vb.net I have find this in VB6 but how can we convert simply this code. thx
2
by: Daylor | last post by:
is there way to change the height of the caption ?
3
by: Jeff | last post by:
for your info - I'm a newbe. Code is at the bottom. Access dbase (each form ca. 10 KB) if my explanations are not enough (probably they aren't). -- access 97 -...
1
by: notregister | last post by:
hi, in VB6 i can change the caption of the form by using frmMain.Caption = "ABC" how do i change it in .NET?? the text i want to change is found at the form1's properties > Appearance> text
2
by: PawelR | last post by:
Hello, I have question about HtmlInputFile. How change caption in HtmlInputFile from "Browse ..." to other? THX PawelR
4
by: Henrootje | last post by:
I have a REPORT with in it a subFORM Now I have this label (lblMonth) that I want to change. How should I do this? What would be the proper event to do this? The lblMonth should contain the...
14
by: windandwaves | last post by:
Hi Folk and Gurus This may help some of you (though probably not the gurus), in changing images: http://www.sunnysideup.co.nz/j/imageChange/ Any feedback appreciated. Cheers
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.