
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.