I've looked around and found a few VBA codes on how to grab the description out of the field's "Description" box, but not how I can use that in a form's properties.
I'd like to have a ControlTip appear with the Description of that field brought from the Description in the database, without having to rewrite all the descriptions; I'm hoping for a copy-paste bit of code that I can add to all controltips?
Something like (but obviously not)
ControlTipText: Me.ThisControl.ThisControlFieldDescription
Anybody know of the code, or even if there is one?
EDIT:
description = Forms("frmTrials").Controls("txtBox").StatusBarText
MsgBox description
The above works to show the status bar text. However I'd like to fill "frmTrials" with the active form and "txtBox" with the currently active control; that way when the control becomes active I can put the StatusBarText into a "Description Box" text field (or the control tip, etc). I tried
description = Forms(Me).Controls(Me.ActiveControl).StatusBarText
which just threw errors at me.
Microsoft Access database fields are created by entering a field name and a field data type in each row of the field entry area of the database table window. The field description is an option to identify the fields purpose; it appears in the status bar during data entry.
For a database object, click Properties on the View menu and enter the description text in the Description box. For tables or queries, you can also enter the description in the table's or query's property sheet.
A relational database like Access usually has several related tables. In a well-designed database, each table stores data about a particular subject, such as employees or products. A table has records (rows) and fields (columns). Fields have different types of data, such as text, numbers, dates, and hyperlinks.
Change data types in Datasheet view Access opens the table in Datasheet view. Select the field (the column) that you want to change. On the Fields tab, in the Properties group, click the arrow in the drop-down list next to Data Type, and then select a data type. Save your changes.
As I understand the situation, you want to set ControlTipText
properties dynamically each time your form loads. Since you indicated in a comment that this application is intended for a tablet device, you might prefer to limit the processor load when opening your form. You could do that by saving the ControlTipText
properties with the form's design.
Try the following procedure with your form's name like this:
SetControlTipText "YourFormName"
Here is the procedure. I didn't find any problems in limited testing. It sets ControlTipText
for check boxes, combos, list boxes, and text boxes. Change the first Case
line to target a different set of controls.
Public Sub SetControlTipText(ByVal pFormName As String)
Dim ctl As Control
Dim db As DAO.Database
Dim frm As Form
Dim rs As DAO.Recordset
DoCmd.OpenForm pFormName, acDesign
Set frm = Forms(pFormName)
If Len(frm.RecordSource) > 0 Then
Set db = CurrentDb
Set rs = db.OpenRecordset(frm.RecordSource)
For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acCheckBox, acComboBox, acListBox, acTextBox
If Len(ctl.ControlSource) > 0 _
And Not ctl.ControlSource Like "=*" Then
ctl.ControlTipText = _
GetDescription(rs.Fields(ctl.ControlSource))
End If
Case Else
' pass '
End Select
Next ctl
rs.Close
End If
Set ctl = Nothing
Set rs = Nothing
Set db = Nothing
Set frm = Nothing
DoCmd.Close acForm, pFormName, acSaveYes
End Sub
SetControlTipText
calls this function:
Public Function GetDescription(ByRef pObject As Object) As String
Dim strReturn As String
On Error GoTo ErrorHandler
strReturn = pObject.Properties("Description")
ExitHere:
GetDescription = strReturn
On Error GoTo 0
Exit Function
ErrorHandler:
strReturn = vbNullString ' make it explicit '
GoTo ExitHere
End Function
That SetControlTipText
procedure ignores unbound forms. If the control source for a bound field doesn't have a Description
property assigned, its ControlTipText
will be set to an empty string.
This approach will require you to run the procedure once for the form, rather than running some other procedure each time the form loads. If you later change Description
properties for any of the form's record source fields, you can re-run SetControlTipText
to update ControlTipText
's.
Or you could run the procedure for all your application's forms as part of your preparations to release a new version of the application.
Dim frm As Object
For Each frm in CurrentProject.AllForms
SetControlTipText frm.Name
Next frm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With