Get Form Properties from Outside of the Form (1 Viewer)

hk1

Registered User.
Local time
Today, 08:16
Joined
Sep 1, 2009
Messages
121
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:

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
 

KenHigg

Registered User
Local time
Today, 10:16
Joined
Jun 9, 2004
Messages
13,327
Trying to imagine why you'd ever need this, not to mention why you'd ever have more than a couple forms open at one time...?
 

hk1

Registered User.
Local time
Today, 08:16
Joined
Sep 1, 2009
Messages
121
I use this information to determine if and when I can close the database during working hours to make changes/updates to it.
 

KenHigg

Registered User
Local time
Today, 10:16
Joined
Jun 9, 2004
Messages
13,327
I see. In the past I have opened a form in the background that stays open and it has a timer event the checks a value in a table on the back end that I change when ever I want all user s to exit for a maint. So when the timer senses it has changed it warns to user to exit in 5 minutes. Then in another five minutes the front closes down via the hidden form timer event... Hope that makes sense...
 

hk1

Registered User.
Local time
Today, 08:16
Joined
Sep 1, 2009
Messages
121
I see. In the past I have opened a form in the background that stays open and it has a timer event the checks a value in a table on the back end that I change when ever I want all user s to exit for a maint. So when the timer senses it has changed it warns to user to exit in 5 minutes. Then in another five minutes the front closes down via the hidden form timer event... Hope that makes sense...

Yes it makes sense but I prefer to do it using a Winsock control since there are a lot of possibilities of what I can program into this thing. Also, there is not network traffic except for when I initiate the traffic.
 

Users who are viewing this thread

Top Bottom