As I understand it, you want to dynamically set the ControlTipText
properties every time your form loads. Since you indicated in the commentary that this application is intended for a tablet device, you can limit the processor load when opening the form. You can do this by saving the ControlTipText
properties using the form design.
Try the following procedure with your form name as follows:
SetControlTipText "YourFormName"
Here is the procedure. I did not find any problems in limited testing. It sets a ControlTipText
for checkboxes, combos, lists, and text fields. Change the first line of the Case
to configure 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
This SetControlTipText
procedure ignores unrelated forms. If the control source for the linked field does not have an assigned Description
property, its ControlTipText
will be set to an empty string.
This approach will require that you execute the procedure once for the form, and not execute any other procedure each time the form loads. If you later change the Description
properties for any of the fields in the form's record source, you can re-run SetControlTipText
to update the ControlTipText
.
Or you can start the procedure for all your application forms in preparation for the release of a new version of the application.
Dim frm As Object For Each frm in CurrentProject.AllForms SetControlTipText frm.Name Next frm