Happy New Year!

Recently I was working on a project where I was implementing form spawning so that my client can see at least two different records using two identical forms, one of the actual forms and the other one a spawned version of itself, (a topic I’ve discussed at my SQL Server with Access meetings, click to join the announcement list!). Because the prior developer did not use form spawning, I had to search all instances in control source of all forms to identify references to the original form and replace it with TempVars.

ADVERTISING
SQL Server Hosting

The project has dozens of forms and thousands of controls, so I created the following code to scan all form record sources for the offending row source and the control source of all controls on the form as well.

Public Sub ScanForms()
On Error Resume Next
Dim obj As AccessObject, dbs As Object
Dim ctrl As Control
Dim strRowsource As String

Set dbs = Application.CurrentProject

For Each obj In dbs.AllForms
'Debug.Print "Working on: " & obj.Name
DoCmd.OpenForm obj.Name, acDesign
strRowsource = Forms(obj.Name).RecordSource
If Err.Number Then
strRowsource = vbNullString
End If
If Len(strRowsource) Then
If InStr(1, strRowsource, "frmPatientProcessing") > 0 Then
Debug.Print "Form: " & obj.Name
End If
End If
For Each ctrl In Forms(obj.Name).Controls
On Error Resume Next
strRowsource = ctrl.ControlSource
If Err.Number Then
strRowsource = vbNullString
End If
On Error GoTo 0
If Len(strRowsource) Then
If InStr(1, strRowsource, "frmPatientProcessing") > 0 Then
Debug.Print "Form: " & obj.Name & " Control:" & ctrl.Name
End If
End If
Next ctrl
DoCmd.Close acForm, obj.Name
Next obj
End Sub