PC Review


Reply
Thread Tools Rate Thread

Read fields caption and description in VBA

 
 
Dale Fye
Guest
Posts: n/a
 
      12th Sep 2009
I'm trying to read a fields caption and description via VBA.

When I iterate through the fields of a table that I know some of the fields
contain descriptions and captions, refering to the property always returns
an error (3270, Property not found).

Do I have to set the property before I can refer to it, even if there is
already text in the property, as seen in the table design view? Or am I
missing something?

Dale




 
Reply With Quote
 
 
 
 
David H
Guest
Posts: n/a
 
      12th Sep 2009
If I recall correctly, YES the property has to be set otherwise you'll get an
error. You can either trap the error if you're referencing the property by
name or you could loop through the properties collection of the field and
check for the property name.



"Dale Fye" wrote:

> I'm trying to read a fields caption and description via VBA.
>
> When I iterate through the fields of a table that I know some of the fields
> contain descriptions and captions, refering to the property always returns
> an error (3270, Property not found).
>
> Do I have to set the property before I can refer to it, even if there is
> already text in the property, as seen in the table design view? Or am I
> missing something?
>
> Dale
>
>
>
>
>

 
Reply With Quote
 
Dale Fye
Guest
Posts: n/a
 
      13th Sep 2009
But if I set the property, won't that overwrite whatever is already in that
property?

I'm confused.

"David H" <(E-Mail Removed)> wrote in message
news:7E8ACA3D-6775-4590-83C8-(E-Mail Removed)...
> If I recall correctly, YES the property has to be set otherwise you'll get
> an
> error. You can either trap the error if you're referencing the property by
> name or you could loop through the properties collection of the field and
> check for the property name.
>
>
>
> "Dale Fye" wrote:
>
>> I'm trying to read a fields caption and description via VBA.
>>
>> When I iterate through the fields of a table that I know some of the
>> fields
>> contain descriptions and captions, refering to the property always
>> returns
>> an error (3270, Property not found).
>>
>> Do I have to set the property before I can refer to it, even if there is
>> already text in the property, as seen in the table design view? Or am I
>> missing something?
>>
>> Dale
>>
>>
>>
>>
>>



 
Reply With Quote
 
David H
Guest
Posts: n/a
 
      13th Sep 2009
Yes. I posted the article to provide you with an example of how to read the
properties and how to trap the error if it occurrs.

"Dale Fye" wrote:

> But if I set the property, won't that overwrite whatever is already in that
> property?
>
> I'm confused.
>
> "David H" <(E-Mail Removed)> wrote in message
> news:7E8ACA3D-6775-4590-83C8-(E-Mail Removed)...
> > If I recall correctly, YES the property has to be set otherwise you'll get
> > an
> > error. You can either trap the error if you're referencing the property by
> > name or you could loop through the properties collection of the field and
> > check for the property name.
> >
> >
> >
> > "Dale Fye" wrote:
> >
> >> I'm trying to read a fields caption and description via VBA.
> >>
> >> When I iterate through the fields of a table that I know some of the
> >> fields
> >> contain descriptions and captions, refering to the property always
> >> returns
> >> an error (3270, Property not found).
> >>
> >> Do I have to set the property before I can refer to it, even if there is
> >> already text in the property, as seen in the table design view? Or am I
> >> missing something?
> >>
> >> Dale
> >>
> >>
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      13th Sep 2009
Your original post states "I know some of the fields contain descriptions
and captions". Yes, you'll get an error on those fields that don't contain
descriptions.

What you can do is set your error handling to ignore the error:

On Error GoTo EH

Dim dbCurr As DAO.Database
Dim tdfCurr As DAO.TableDef
Dim fldCurr As DAO.Field
Dim prpCurr As DAO.Property
Dim varDescription As Variant

Set dbCurr = CurrentDb()
For Each tdfCurr In dbCurr.TableDefs
Debug.Print "Fields in Table " & tdfCurr.Name & ":"
For Each fldCurr In tdfCurr.Fields
strDescription = fldCurr.Properties("Description")
Debug.Print " " & fldCurr.Name & (" (" + varDescription & ")")
Next fldCurr
Next tdfCurr

EndIt:
Set prpCurr = Nothing
Set fldCurr = Nothing
Set tdfCurr = Nothing
Set dbCurr = Nothing
Exit Sub

EH:
Select Case Err.Number
Case 3270 ' Property Not Found
varDescription = Null
Resume Next
Case Else
MsgBox Err.Number & ": " & Err.Description
Resume EndIt
End Select




--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Dale Fye" <(E-Mail Removed)> wrote in message
news:O3oAWz$(E-Mail Removed)...
> But if I set the property, won't that overwrite whatever is already in
> that property?
>
> I'm confused.
>
> "David H" <(E-Mail Removed)> wrote in message
> news:7E8ACA3D-6775-4590-83C8-(E-Mail Removed)...
>> If I recall correctly, YES the property has to be set otherwise you'll
>> get an
>> error. You can either trap the error if you're referencing the property
>> by
>> name or you could loop through the properties collection of the field and
>> check for the property name.
>>
>>
>>
>> "Dale Fye" wrote:
>>
>>> I'm trying to read a fields caption and description via VBA.
>>>
>>> When I iterate through the fields of a table that I know some of the
>>> fields
>>> contain descriptions and captions, refering to the property always
>>> returns
>>> an error (3270, Property not found).
>>>
>>> Do I have to set the property before I can refer to it, even if there is
>>> already text in the property, as seen in the table design view? Or am I
>>> missing something?
>>>
>>> Dale
>>>
>>>
>>>
>>>
>>>

>
>



 
Reply With Quote
 
Dale Fye
Guest
Posts: n/a
 
      14th Sep 2009
Thanks, Doug.

I was using similar code, but was doing my error trapping in line.

On Error Resume Next
For Each fld In tdf.Fields
varDesc = fld.Properties("Description")
If Err.Number <> 0 Then
varDesc = "not available"
' Err.Clear
End If
varCaption = fld.Properties("Caption")
If Err.Number <> 0 Then
varCaption = "not available"
' Err.Clear
End If
Debug.Print fld.Name, varDesc, varCaption
Next

What is interesting is that if I failed to clear the error, then it was
never resetting the Err and was always entering the If/End If sequences. As
soon as I added the Err.Clear lines, it worked the way I was expecting. I
don't use in-line error handling very often, but this will be a reminder to
clear the error as soon as I test for it.

Dale

"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_gmail.com> wrote in message
news:(E-Mail Removed)...
> Your original post states "I know some of the fields contain descriptions
> and captions". Yes, you'll get an error on those fields that don't contain
> descriptions.
>
> What you can do is set your error handling to ignore the error:
>
> On Error GoTo EH
>
> Dim dbCurr As DAO.Database
> Dim tdfCurr As DAO.TableDef
> Dim fldCurr As DAO.Field
> Dim prpCurr As DAO.Property
> Dim varDescription As Variant
>
> Set dbCurr = CurrentDb()
> For Each tdfCurr In dbCurr.TableDefs
> Debug.Print "Fields in Table " & tdfCurr.Name & ":"
> For Each fldCurr In tdfCurr.Fields
> strDescription = fldCurr.Properties("Description")
> Debug.Print " " & fldCurr.Name & (" (" + varDescription & ")")
> Next fldCurr
> Next tdfCurr
>
> EndIt:
> Set prpCurr = Nothing
> Set fldCurr = Nothing
> Set tdfCurr = Nothing
> Set dbCurr = Nothing
> Exit Sub
>
> EH:
> Select Case Err.Number
> Case 3270 ' Property Not Found
> varDescription = Null
> Resume Next
> Case Else
> MsgBox Err.Number & ": " & Err.Description
> Resume EndIt
> End Select
>
>
>
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "Dale Fye" <(E-Mail Removed)> wrote in message
> news:O3oAWz$(E-Mail Removed)...
>> But if I set the property, won't that overwrite whatever is already in
>> that property?
>>
>> I'm confused.
>>
>> "David H" <(E-Mail Removed)> wrote in message
>> news:7E8ACA3D-6775-4590-83C8-(E-Mail Removed)...
>>> If I recall correctly, YES the property has to be set otherwise you'll
>>> get an
>>> error. You can either trap the error if you're referencing the property
>>> by
>>> name or you could loop through the properties collection of the field
>>> and
>>> check for the property name.
>>>
>>>
>>>
>>> "Dale Fye" wrote:
>>>
>>>> I'm trying to read a fields caption and description via VBA.
>>>>
>>>> When I iterate through the fields of a table that I know some of the
>>>> fields
>>>> contain descriptions and captions, refering to the property always
>>>> returns
>>>> an error (3270, Property not found).
>>>>
>>>> Do I have to set the property before I can refer to it, even if there
>>>> is
>>>> already text in the property, as seen in the table design view? Or am
>>>> I
>>>> missing something?
>>>>
>>>> Dale
>>>>
>>>>
>>>>
>>>>
>>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Photo Gallery caption or description not seen =?Utf-8?B?eWVzeWVzNQ==?= Microsoft Frontpage 3 20th Oct 2006 10:17 AM
How read or write the Caption of table fields? Fjordur Microsoft Access 1 19th May 2006 12:57 PM
Photo Gallery Properties, caption and description DaveC Microsoft Frontpage 4 5th Dec 2005 04:19 PM
Caption vs Description in photogallery stealthy_tanuki@-remove-yahoo.com Microsoft Frontpage 1 3rd Oct 2004 09:25 AM
Re: photo gallery caption/description didn't show E. T. Culling Microsoft Frontpage 0 4th Sep 2003 05:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:44 PM.