I'm trying to program a short function in a stand-alone code module that will iterate through all forms and their subforms and return a human-readable string that tells me which forms are Dirty or in NewRecord state. So far I'm not having success, especially on the subforms.
Can someone help me make this code work or is there a better/cleaner way to achieve this?
Here's the code I do have:
Can someone help me make this code work or is there a better/cleaner way to achieve this?
Here's the code I do have:
Code:
Public Function fReturnDatabaseStatus() As String
Dim s As String
'On Error Resume Next
Dim i As Integer
Dim db As Access.Application
Dim frm As Form, ctl As Control
Set db = Application
For i = db.Forms.Count - 1 To 0 Step -1
Set frm = db.Forms(i)
If fIsFormOpen(frm.Name) = True Then
s = s & frm.Name
If Nz(Forms(frm.Name).RecordSource, "") <> "" Then
s = s & ": Dirty=" & Forms(frm.Name).Dirty
s = s & " NewRecord=" & frm.NewRecord
s = s & " Visible=" & frm.Visible & vbCrLf
End If
For Each ctl In frm.Controls
If ctl.ControlType = 112 Then 'Is a subform
s = s & " -" & ctl.Name & ":" & ctl.SourceObject & vbCrLf
'This line of code is red - it does not work
If Forms(frm.Name)!(ctl.Name).RecordSource <> "" Then
'Want to check the Dirty and NewRecord properties here
End If
End If
Next
Else
s = s & frm.Name & ":Closed" & vbCrLf
End If
Next
fReturnDatabaseStatus = s
End Function