Access97 Field Attributes that are not in the Attributes collection of that Field 
Author Message
 Access97 Field Attributes that are not in the Attributes collection of that Field

How can I access attributes of a field that are
not in the attributes collection for that field?

I am using VB6

    Rem Display other Field ATTRIBUTES
    List1.AddItem "        Allow Zero-Length: " & fld.AllowZeroLength
    List1.AddItem "             Source Table: " & fld.SourceTable
    List1.AddItem "         Ordinal Position: " & fld.OrdinalPosition
    List1.AddItem "          Collating Order: " & fld.CollatingOrder
    List1.AddItem "                 Required: " & fld.Required
    List1.AddItem "                     desc: " & fld.Description

but it bombs on the last line...



Wed, 10 Mar 2004 22:23:22 GMT  
 Access97 Field Attributes that are not in the Attributes collection of that Field


Quote:
>How can I access attributes of a field that are
>not in the attributes collection for that field?

>I am using VB6

>    Rem Display other Field ATTRIBUTES
>    List1.AddItem "        Allow Zero-Length: " & fld.AllowZeroLength
>    List1.AddItem "             Source Table: " & fld.SourceTable
>    List1.AddItem "         Ordinal Position: " & fld.OrdinalPosition
>    List1.AddItem "          Collating Order: " & fld.CollatingOrder
>    List1.AddItem "                 Required: " & fld.Required
>    List1.AddItem "                     desc: " & fld.Description

>but it bombs on the last line...

I wrote the following in answer to a question about how to set a
database's AppTitle property from code, but it's relevant to your
question because Description is an Access-defined property. You can
apply what I say here (about using CreateProperty) to your problem:

AppTitle is an Access-defined property. This means that it is not a
builtin property of a Jet database, and is not available until either
Access creates it, or you create it in code. Just to illustrate what I
mean, open a module and paste this code in:

Sub enumproperties()
Dim db As Database
Dim prp As Property
On Error Resume Next
Set db = CreateDatabase("db5", dbLangGeneral, dbVersion30)
'Debug.Print "Immediately after creating database"
'Debug.Print "After accessing startup properties"
Debug.Print "After accessing startup properties and setting app title"
For Each prp In db.Properties
    Debug.Print prp.Name, prp.Value
Next prp
End Sub

Uncomment the first debug.print statement and comment out the second
and third. Run the code (by clicking the Run toolbar button or
pressing F5). Press ctrl-G to bring up the debug window. This is what
it should contain:

Immediately after creating database
Name          C:\My Documents\db5.mdb
Connect
Transactions  True
Updatable     True
CollatingOrder               1033
QueryTimeout   60
Version       3.0
RecordsAffected              0
ReplicaID
DesignMasterID

These are the builtin properties of a Jet database. Now, open another
instance of Access and open the new database and close it. Come back
to the first instance of Access, change the code to:
Sub enuproperties()
Dim db As Database
Dim prp As Property
On Error Resume Next
Set db = OpenDatabase("db5")
Debug.Print "Immediately after opening database in Access for first
time"
'Debug.Print "After accessing startup properties"
'Debug.Print "After accessing startup properties and setting app
title"
For Each prp In db.Properties
    Debug.Print prp.Name, prp.Value
Next prp
End Sub

When you run the code this is what you should see:
Immediately after opening database in Access for first time
<snip>
AccessVersion 07.53
Build          4122

You now see the first Access-created propertes: AccessVersion and
Build. Go back to the second instance, reopen db5 and open the Startup
properties dialog. Click OK to close it without changing anything. Go
back to the first instance, comment the first debug.print, uncomment
the second, and run it.

this is what you should see:

After accessing startup properties
<snip>
StartUpShowDBWindow         True
StartUpShowStatusBar        True
AllowShortcutMenus          True
AllowFullMenus              True
AllowBuiltInToolbars        True
AllowToolbarChanges         True
AllowBreakIntoCode          True
AllowSpecialKeys            True

You can now see some more properties. Note that they were assigned
default values. Go back to the second instance, open the Startup
properties, type "New Title" in the Application Title box. Click OK.
Run the code again. This time you will see AppTitle in the debug
window.

So - does this mean that you have to use Access to define and set
these properties?

No.
You can use CreateProperty to create the property yourself, and Append
to append it to the new database's Properties collection. Like this:

Set db = CreateDatabase("db6", dbLangGeneral, dbVersion30)
Set prp = db.CreateProperty("AppTitle","My App Title")
db.Properties.Append prp

HTH,
Bob Barrows
Please reply to the newsgroup. My reply-to address is my "spam trap" and I don't check it very often.



Wed, 10 Mar 2004 23:38:52 GMT  
 Access97 Field Attributes that are not in the Attributes collection of that Field
Jim,

The Description is not a built in Jet capability, it is
created by Access only when something is typed into the
description area in table design view.  Of course the
property can be created programatically too, but you
probably don't care about that.

The only method I know of to deal with this issue is to use
error trapping.  I don't know about VB6, but in Access it
can be as simple as:

On Error Resume Next
strDesc = fld.Description
If Err.Number = 0 Then
    List1.AddItem "                     desc: " & strDesc
Else        ' 3270 is Property not found
    List1.AddItem "                     desc: "
End If

Marsh

Quote:

>How can I access attributes of a field that are
>not in the attributes collection for that field?

>I am using VB6

>    Rem Display other Field ATTRIBUTES
>    List1.AddItem "        Allow Zero-Length: " &
fld.AllowZeroLength
>    List1.AddItem "             Source Table: " &
fld.SourceTable
>    List1.AddItem "         Ordinal Position: " &
fld.OrdinalPosition
>    List1.AddItem "          Collating Order: " &
fld.CollatingOrder
>    List1.AddItem "                 Required: " &
fld.Required
>    List1.AddItem "                     desc: " &
fld.Description

>but it bombs on the last line...



Wed, 10 Mar 2004 23:28:18 GMT  
 Access97 Field Attributes that are not in the Attributes collection of that Field


Quote:
> How can I access attributes of a field that are
> not in the attributes collection for that field?

> I am using VB6

>     Rem Display other Field ATTRIBUTES
>     List1.AddItem "        Allow Zero-Length: " & fld.AllowZeroLength
>     List1.AddItem "             Source Table: " & fld.SourceTable
>     List1.AddItem "         Ordinal Position: " & fld.OrdinalPosition
>     List1.AddItem "          Collating Order: " & fld.CollatingOrder
>     List1.AddItem "                 Required: " & fld.Required
>     List1.AddItem "                     desc: " & fld.Description

You would need to create a list of all possible field attributes and their
values and persist it somehow, either in a table, or in a resourse file, or
just create an array in code.

Then you would loop over all those possible attributes and compare them
with the attributes of the actual field being examined in the following
way:

For Each SomeAttributeValue In Collection|Array|Recordset
  If field.Attributes And SomeAttributeValue = SomeAttributeValue Then
    List1.Add SomeAttributeName
Next SomeAttributeValue

--
(remove a 9 to reply by email)



Wed, 10 Mar 2004 23:53:28 GMT  
 Access97 Field Attributes that are not in the Attributes collection of that Field

Jim-

Last line bombs because there is no fld.description.  Instead, it is
at fld.properties("Description").  The problem is that if Description
is blank, you get 3270 error (object not found).

Several ways to correct.  Here is simple workaround.

In declaration, add:
Dim fielddescription as string

'Then, in body of code:

Fielddescription = " "
On Error Resume Next
Fielddescription = fld.properties("Description")
If Err = 3270 Or fielddescription = " " Then '3270 = object not found
   fielddescription = "No description provided."
   Err = 0
End If

'finally

    List1.AddItem "        Allow Zero-Length: " & fld.AllowZeroLength
    List1.AddItem "             Source Table: " & fld.SourceTable
    List1.AddItem "         Ordinal Position: " & fld.OrdinalPosition
    List1.AddItem "          Collating Order: " & fld.CollatingOrder
    List1.AddItem "                 Required: " & fld.Required
    List1.AddItem "                     desc: " & fielddescription



Thu, 11 Mar 2004 05:09:40 GMT  
 Access97 Field Attributes that are not in the Attributes collection of that Field
...this complains that fld.Description is a
"Method or data member" that is "not found"
Quote:
> The only method I know of to deal with this issue is to use
> error trapping.  I don't know about VB6, but in Access it
> can be as simple as:

> On Error Resume Next
> strDesc = fld.Description
> If Err.Number = 0 Then
>     List1.AddItem "                     desc: " & strDesc
> Else        ' 3270 is Property not found
>     List1.AddItem "                     desc: "
> End If

> Marsh



Thu, 11 Mar 2004 08:48:00 GMT  
 Access97 Field Attributes that are not in the Attributes collection of that Field
Yes!
Thanks so very much!!!
I hope to one day be as helpful to another.



Quote:

> Jim-

> Last line bombs because there is no fld.description.  Instead, it is
> at fld.properties("Description").  The problem is that if Description
> is blank, you get 3270 error (object not found).

> Several ways to correct.  Here is simple workaround.

> In declaration, add:
> Dim fielddescription as string

> 'Then, in body of code:

> Fielddescription = " "
> On Error Resume Next
> Fielddescription = fld.properties("Description")
> If Err = 3270 Or fielddescription = " " Then '3270 = object not found
>    fielddescription = "No description provided."
>    Err = 0
> End If

> 'finally

>     List1.AddItem "        Allow Zero-Length: " & fld.AllowZeroLength
>     List1.AddItem "             Source Table: " & fld.SourceTable
>     List1.AddItem "         Ordinal Position: " & fld.OrdinalPosition
>     List1.AddItem "          Collating Order: " & fld.CollatingOrder
>     List1.AddItem "                 Required: " & fld.Required
>     List1.AddItem "                     desc: " & fielddescription



Thu, 11 Mar 2004 08:53:34 GMT  
 Access97 Field Attributes that are not in the Attributes collection of that Field
Arghh, I'm always forgetting that it should be
fld.Properties("Description")

Sorry about that,
    Marsh

Quote:

>...this complains that fld.Description is a
>"Method or data member" that is "not found"

>> The only method I know of to deal with this issue is to
use
>> error trapping.  I don't know about VB6, but in Access it
>> can be as simple as:

>> On Error Resume Next
>> strDesc = fld.Description
>> If Err.Number = 0 Then
>>     List1.AddItem "                     desc: " & strDesc
>> Else        ' 3270 is Property not found
>>     List1.AddItem "                     desc: "
>> End If

>> Marsh



Thu, 11 Mar 2004 23:19:52 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Report on field attributes, not content

2. Global Address List showing Custom Attribute fields

3. Change table field attributes using vba

4. Attribute of an Index No Duplicates field ???

5. Setting Field Attributes

6. font attributes in text & memo fields

7. Setting Field Attributes

8. Can I Change attributes in Unbound Text field?

9. How to Change Field Attributes in Reports

10. Setting the field attribute


 
Powered by phpBB® Forum Software © phpBB Group