Access Calculated Control Blank/Empty/Null

Now the following is for a very niche market, but I thought I’d share none the less.

Access 2010 (although I seen reports in other versions such as Access 2013) had a major issue in which calculated control would not display their content. Yet, if you clicked on the control, it would then display the proper value. Now Microsoft eventually remedied the issue by issuing an update (I believe https://support.microsoft.com/en-us/help/2827138/access-encounters-multiple-issues-if-the-pc-has-been-running-more-than). So there is a real solution available, which is to update your installation.

However, I had a client, whose IT Dept. would not, will not, install the updates and I left me with no choice but to come up with a workaround of my own. As such, I created a routine that simply goes through a form and sets the focus on each control, one by one. It’s not ideal, but it works.

'---------------------------------------------------------------------------------------
' Procedure : Frm_TouchMe
' Author    : Daniel Pineault, CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Goes through a form and sets the focus on each control, one by one
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
'             (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: Uses Late Binding, so none required
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' frm       : Form object to go through
'
' Usage:
' ~~~~~~
' Call Frm_TouchMe(Me)
' Call Frm_TouchMe(Me.frm_Orders.Form)
'
' Revision History:
' Rev       Date(yyyy/mm/dd)        Description
' **************************************************************************************
' 1         2017-08-18              Initial Release
'---------------------------------------------------------------------------------------
Public Sub Frm_TouchMe(frm As Access.Form)
10        On Error GoTo Error_Handler
          Dim ctl                   As Access.Control

20        With frm.Recordset
30            If .RecordCount <> 0 Then
40                .MoveFirst
50                Do While Not .EOF
60                    For Each ctl In frm.Controls
70                        If ctl.ControlType = acCheckBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acTextBox Then
80                            If ctl.Enabled = True And ctl.Visible = True Then
90                                If frm.DefaultView = 2 Then    'Datasheet
100                                   If ctl.ColumnHidden = False Then
110                                       ctl.SetFocus
120                                   End If
130                               Else
140                                   ctl.SetFocus
150                               End If
160                           End If
170                       End If
180                       DoEvents 'This is necessary otherwise the results were not always consistent
190                   Next ctl
200                   .MoveNext
210               Loop
220               .MoveFirst
230           End If
240       End With

Error_Handler_Exit:
250       On Error Resume Next
260       If Not ctl Is Nothing Then Set ctl = Nothing
270       If Not frm Is Nothing Then Set frm = Nothing
280       Exit Sub

Error_Handler:
290       MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
                 "Error Number: " & Err.Number & vbCrLf & _
                 "Error Source: Frm_TouchMe" & vbCrLf & _
                 "Error Description: " & Err.Description & _
                 Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
                 , vbOKOnly + vbCritical, "An Error has Occurred!"
300       Resume Error_Handler_Exit
End Sub

In my case, the forms that were impacted by this issue were subforms, so I created a Load event in the parent forms and simply called the function by doing something like:

Call Frm_TouchMe(Me.frm_Orders.Form)

Et voilà! The problem was no more.

One Word of Caution
Because this effectively loops through all the records and controls, one by one and executes DoEvents each time, this can impact performance and would not be recommended for forms with huge amounts of records (big datasheets for instances).

The proper resolution remains to update Office!