How to get Table Description Field Text to show on Forms? Hovering? Right-Click?

M

MyEmailList

Can I get the fioeld description I enter in the Table Design View to
show on Forms or Queries?

When the mouse hovers over the field or field name??

When the user right clicks on the field or field name??

At the bottom of the screen when the mouse hovers?

How?

Thanks for any help.

Mel
 
G

Guest

For a generic solution add the following function to a standard module:

Public Function GetFieldDescription(strTable As String, strField As String)
As String

Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Set dbs = CurrentDb
Set tdf = dbs.TableDefs(strTable)
Set fld = tdf.Fields(strField)

GetFieldDescription = fld.Properties("Description")

End Function

And in a form's Open event procedure call the function, passing the table
and field name into it, to assign the return value to the control's
ControlTipText property, e.g.


Me.MyControl.ControlTipText = GetFieldDescription("[MyTable]",
"[MyField]")

Note that the Description property of the field in question must have been
created by assigning it a value in table design view. Otherwise an error
will occur

Ken Sheridan
Stafford, England
 
M

MyEmailList

Ken,

I've done some programming but not much in Access.

How do I (where do I click) to add a function to the "standard
module" ???

And, am I correct in understanding that the first function would be
called each time the db opened?

And the 2nd function would be called each time the form opened??

thanks again.

Mel
 
G

Guest

Mel:

To add the GetFieldDescription function to a standard module go to the
modules page of the database window and select New. The VBA editor will open
at a new module with a couple of lines already in place. Copy the following
code to the clipboard and paste it in immediately below the existing lines in
the module. The first line form 'Public' to the final 'As String' is all one
line, but might have split into two in your newsgroup reader, so watch out
for this and correct it after pasting in if necessary. Then save the module
under a name of your choice, but not the same name as the function; I
generally give module names a 'bas' prefix, e.g. basUtilities, to avoid any
confusion with other object names.

Public Function GetFieldDescription(strTable As String, strField As String)
As String

Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Set dbs = CurrentDb
Set tdf = dbs.TableDefs(strTable)
Set fld = tdf.Fields(strField)

GetFieldDescription = fld.Properties("Description")

End Function

The second line of code is not part of a function; it goes in each relevant
form's Open event procedure, and you'll need to repeat it for each control
for which you want to show the field description as a tool tip. So open the
form in design view and open its properties sheet if its not already open.
On the Event tab of the properties sheet select the On Open event property
and click on the 'build' button (the one on the right with 3 dots). Select
'Code Builder' in the dialogue and OK out. This will open the VBA editor at
the Open event procedure in the form's class module. The first and last
lines will be in place already. Enter variations on the following as new
lines between the existing two, one line for each control in question, and
change the control, table and field names from MyControl, MyTable and MyField
in each line as necessary. Note again that this should be all one line if
its been split in your reader:

Me.MyControl.ControlTipText = GetFieldDescription("[MyTable]", "[MyField]")

The form's Open event procedure executes when you open a form. This then
calls the GetFieldDescription function however many times are necessary, i.e.
once for each relevant control, and assigns the value of the relevant field's
Description property to the control's ToolTipText property. The tool tip
with the appropriate description will then show when a user moves the mouse
pointer over the control.

Functions or procedures in a standard module are not called when the
database opens, but when explicitly called, as above. Sometimes, however,
you might want a function or procedure to be called immediately when the
database is opened, e.g. to check if links to tables in a shared back end are
still valid. There are various ways you can do this, e.g. by an autoexec
macro or by including code in the Open event of a form such as a switchboard
set as the database's opening form.

Sometimes you might want other functions or procedures to be called when a
database closes, e.g. to perform some tidying up housework tasks. A way to
do this id to use a hidden form as the database's opening form and call the
functions or procedures in its Close event procedure. The form will stay
open, but hidden, throughout the session, but will close when the database
closes, executing its Close event procedure to call the housework functions
or procedures.

Ken Sheridan
Stafford, England
 
D

Douglas J. Steele

You might want to put some error trapping in that function:

Public Function GetFieldDescription( _
strTable As String, _
strField As String _
) As String

On Error GoTo Err_GetFieldDescription

Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim strDesc As String

Set dbs = CurrentDb
Set tdf = dbs.TableDefs(strTable)
Set fld = tdf.Fields(strField)
strDesc = fld.Properties("Description")

End_GetFieldDescription:
GetFieldDescription = strDesc
Exit Function

Err_GetFieldDescription:
' 3265 is "Item Not Found In This Collection"
' (i.e.: either the table name or the field name is incorrect)
' 3270 is "Property Not Found"
' (i.e.: no description was set for the field.)
Select Case Err.Number
Case 3265
strDesc = "Invalid Table or Field name."

Resume Next
Case 3270
strDesc = "No Description found."
Resume Next
Case Else
Err.Raise Err.Number, _
"GetFieldDescription", _
Err.Description
Resume End_GetFieldDescription
End Select

End Function


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ken Sheridan said:
Mel:

To add the GetFieldDescription function to a standard module go to the
modules page of the database window and select New. The VBA editor will
open
at a new module with a couple of lines already in place. Copy the
following
code to the clipboard and paste it in immediately below the existing lines
in
the module. The first line form 'Public' to the final 'As String' is all
one
line, but might have split into two in your newsgroup reader, so watch out
for this and correct it after pasting in if necessary. Then save the
module
under a name of your choice, but not the same name as the function; I
generally give module names a 'bas' prefix, e.g. basUtilities, to avoid
any
confusion with other object names.

Public Function GetFieldDescription(strTable As String, strField As
String)
As String

Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Set dbs = CurrentDb
Set tdf = dbs.TableDefs(strTable)
Set fld = tdf.Fields(strField)

GetFieldDescription = fld.Properties("Description")

End Function

The second line of code is not part of a function; it goes in each
relevant
form's Open event procedure, and you'll need to repeat it for each control
for which you want to show the field description as a tool tip. So open
the
form in design view and open its properties sheet if its not already open.
On the Event tab of the properties sheet select the On Open event property
and click on the 'build' button (the one on the right with 3 dots).
Select
'Code Builder' in the dialogue and OK out. This will open the VBA editor
at
the Open event procedure in the form's class module. The first and last
lines will be in place already. Enter variations on the following as new
lines between the existing two, one line for each control in question, and
change the control, table and field names from MyControl, MyTable and
MyField
in each line as necessary. Note again that this should be all one line if
its been split in your reader:

Me.MyControl.ControlTipText = GetFieldDescription("[MyTable]",
"[MyField]")

The form's Open event procedure executes when you open a form. This then
calls the GetFieldDescription function however many times are necessary,
i.e.
once for each relevant control, and assigns the value of the relevant
field's
Description property to the control's ToolTipText property. The tool tip
with the appropriate description will then show when a user moves the
mouse
pointer over the control.

Functions or procedures in a standard module are not called when the
database opens, but when explicitly called, as above. Sometimes, however,
you might want a function or procedure to be called immediately when the
database is opened, e.g. to check if links to tables in a shared back end
are
still valid. There are various ways you can do this, e.g. by an autoexec
macro or by including code in the Open event of a form such as a
switchboard
set as the database's opening form.

Sometimes you might want other functions or procedures to be called when a
database closes, e.g. to perform some tidying up housework tasks. A way
to
do this id to use a hidden form as the database's opening form and call
the
functions or procedures in its Close event procedure. The form will stay
open, but hidden, throughout the session, but will close when the database
closes, executing its Close event procedure to call the housework
functions
or procedures.

Ken Sheridan
Stafford, England

Ken,

I've done some programming but not much in Access.

How do I (where do I click) to add a function to the "standard
module" ???

And, am I correct in understanding that the first function would be
called each time the db opened?

And the 2nd function would be called each time the form opened??

thanks again.

Mel
 
G

Guest

In a situation like this I'd tend to let the error handler in the calling
procedure, i.e. the form's Open event procedure, deal with it. I'd be
interested to hear your comments on that approach.

Ken Sheridan
Stafford, England

Douglas J. Steele said:
You might want to put some error trapping in that function:

Public Function GetFieldDescription( _
strTable As String, _
strField As String _
) As String

On Error GoTo Err_GetFieldDescription

Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim strDesc As String

Set dbs = CurrentDb
Set tdf = dbs.TableDefs(strTable)
Set fld = tdf.Fields(strField)
strDesc = fld.Properties("Description")

End_GetFieldDescription:
GetFieldDescription = strDesc
Exit Function

Err_GetFieldDescription:
' 3265 is "Item Not Found In This Collection"
' (i.e.: either the table name or the field name is incorrect)
' 3270 is "Property Not Found"
' (i.e.: no description was set for the field.)
Select Case Err.Number
Case 3265
strDesc = "Invalid Table or Field name."

Resume Next
Case 3270
strDesc = "No Description found."
Resume Next
Case Else
Err.Raise Err.Number, _
"GetFieldDescription", _
Err.Description
Resume End_GetFieldDescription
End Select

End Function


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ken Sheridan said:
Mel:

To add the GetFieldDescription function to a standard module go to the
modules page of the database window and select New. The VBA editor will
open
at a new module with a couple of lines already in place. Copy the
following
code to the clipboard and paste it in immediately below the existing lines
in
the module. The first line form 'Public' to the final 'As String' is all
one
line, but might have split into two in your newsgroup reader, so watch out
for this and correct it after pasting in if necessary. Then save the
module
under a name of your choice, but not the same name as the function; I
generally give module names a 'bas' prefix, e.g. basUtilities, to avoid
any
confusion with other object names.

Public Function GetFieldDescription(strTable As String, strField As
String)
As String

Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Set dbs = CurrentDb
Set tdf = dbs.TableDefs(strTable)
Set fld = tdf.Fields(strField)

GetFieldDescription = fld.Properties("Description")

End Function

The second line of code is not part of a function; it goes in each
relevant
form's Open event procedure, and you'll need to repeat it for each control
for which you want to show the field description as a tool tip. So open
the
form in design view and open its properties sheet if its not already open.
On the Event tab of the properties sheet select the On Open event property
and click on the 'build' button (the one on the right with 3 dots).
Select
'Code Builder' in the dialogue and OK out. This will open the VBA editor
at
the Open event procedure in the form's class module. The first and last
lines will be in place already. Enter variations on the following as new
lines between the existing two, one line for each control in question, and
change the control, table and field names from MyControl, MyTable and
MyField
in each line as necessary. Note again that this should be all one line if
its been split in your reader:

Me.MyControl.ControlTipText = GetFieldDescription("[MyTable]",
"[MyField]")

The form's Open event procedure executes when you open a form. This then
calls the GetFieldDescription function however many times are necessary,
i.e.
once for each relevant control, and assigns the value of the relevant
field's
Description property to the control's ToolTipText property. The tool tip
with the appropriate description will then show when a user moves the
mouse
pointer over the control.

Functions or procedures in a standard module are not called when the
database opens, but when explicitly called, as above. Sometimes, however,
you might want a function or procedure to be called immediately when the
database is opened, e.g. to check if links to tables in a shared back end
are
still valid. There are various ways you can do this, e.g. by an autoexec
macro or by including code in the Open event of a form such as a
switchboard
set as the database's opening form.

Sometimes you might want other functions or procedures to be called when a
database closes, e.g. to perform some tidying up housework tasks. A way
to
do this id to use a hidden form as the database's opening form and call
the
functions or procedures in its Close event procedure. The form will stay
open, but hidden, throughout the session, but will close when the database
closes, executing its Close event procedure to call the housework
functions
or procedures.

Ken Sheridan
Stafford, England

Ken,

I've done some programming but not much in Access.

How do I (where do I click) to add a function to the "standard
module" ???

And, am I correct in understanding that the first function would be
called each time the db opened?

And the 2nd function would be called each time the form opened??

thanks again.

Mel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top