ACC2: Reference to Field's Caption Property Can Cause an ErrorID: Q132019
|
Advanced: Requires expert coding, interoperability, and multiuser skills.
You may receive an error message if you reference a field's Caption
property when the following two conditions are true for the Caption
property:
Form: Test1
------------------
Caption: TestForm1
Command button:
Name: ButtonTest
Caption: Test
OnClick: [Event Procedure]
Sub ButtonTest_Click ()
On Local Error Resume Next
Dim i As Integer, UserMessage As String
Dim db As Database, tdef As TableDef
Dim fld As Field, prp As Property
Dim TestCaption As String
Set db = dbEngine.Workspaces(0).Databases(0)
' Test the local table.
Set tdef = db.Tabledefs("LocalProducts")
Set fld = tdef.Fields("Product ID")
TestCaption = fld.Properties("Caption")
If Err = 3270 Then ' Caption does not exist.
UserMessage = "The LocalProducts Tables Caption Property_
is Null!"
Else
UserMessage = "The LocalProducts Table's Caption is [" &_
TestCaption & "]"
End If
MsgBox UserMessage
' Test the attached table.
Set tdef = db.Tabledefs("AttachedProducts")
Set fld = tdef.Fields("Product ID")
TestCaption = fld.Properties("Caption")
If Err = 3270 Then ' Caption does not exist
UserMessage = "The AttachedProducts Table's Caption Property_
is Null!"
Else
UserMessage = "The AttachedProducts Table's Caption is [" &_
TestCaption & "]"
End If
MsgBox UserMessage
ButtonTest_Click_End:
Exit Sub
ButtonTest_Click_Err:
MsgBox Error$
Resume ButtonTest_Click_End
End Sub
The LocalProducts Table's Caption Property is Null!
The AttachedProducts Table's Caption Property is Null!
The LocalProducts Table's Caption is [LocalProducts Caption]
The AttachedProducts Table's Caption Property is Null!
The LocalProducts Table's Caption is [LocalProducts Caption]
The AttachedProducts Table's Caption Property is Null!
Form: Test2
------------------
Caption: TestForm2
Command button:
Name: ButtonTest
Caption: Test
OnClick: [Event Procedure]
Sub ButtonTest_Click ()
On Local Error Resume Next
Dim i As Integer, UserMessage As String
Dim db As Database, tdef As TableDef
Dim fld As Field, prp As Property
Dim TestCaption As String
Set db = dbEngine.Workspaces(0).Databases(0)
' Test the local table.
Set tdef = db.Tabledefs("LocalProducts")
Set fld = tdef.Fields("Product ID")
TestCaption = fld.Properties("Caption")
If Err = 3270 Then ' Caption does not exist
UserMessage = "The LocalProducts Tables Caption Property_
is Null!"
Else
UserMessage = "The LocalProducts Table's Caption is [" &_
TestCaption & "]"
End If
MsgBox UserMessage
' Test the attached table using the OpenDatabase method.
Set db = OpenDatabase("C:\ACCESS\SAMPAPPS\NWIND.MDB")
Set tdef = db.Tabledefs("Products")
Set fld = tdef.Fields("Product ID")
TestCaption = fld.Properties("Caption")
If Err = 3270 Then ' Caption does not exist.
UserMessage = "The AttachedProducts Table's Caption Property_
is Null!"
Else
UserMessage = "The AttachedProducts Table's Caption is [" &_
TestCaption & "]"
End If
MsgBox UserMessage
ButtonTest_Click_End:
Exit Sub
ButtonTest_Click_Err:
MsgBox Error$
Resume ButtonTest_Click_End
End Sub
The LocalProducts Table's Caption is [LocalProducts Caption]
The AttachedProducts Table's Caption is [AttachedProducts Caption]
Microsoft Access "Building Applications," version 2.0, Chapter 5, "Access
Basic Fundamentals" pages 113-132
Microsoft Access "Building Applications," version 2.0, Chapter 7, "Object
and Collections" pages 155-181
Microsoft Access "Building Applications," version 2.0, Chapter 10,
"Handling Run-Time Errors" pages 221-238
For more information about the Field object, search for "Field," and then
"Field Object, Fields Collection" using the Microsoft Access Help menu.
For more information about the Caption Property, search for "Caption," and
then "Caption Property" using the Microsoft Access Help menu.
Keywords : kberrmsg kbprg MdlDao TblFldp
Version : 2.0
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: May 3, 1999