'============================================================ ' GlobalStatus ' ----------------------------------------------------------- ' Appends a message to the active forms "StatusBox" control, ' or, if thats missing, finds the first open form that has one. ' ' If no suitable form is found, it shows the message in a MsgBox. ' ' DESIGN GOALS: ' - Global usability (no form hardcoding) ' - Safe if form is closed or control missing ' - Thread-safe via DoEvents '============================================================ Public Sub GlobalStatus(ByVal s As Variant) On Error Resume Next
Dim frm As Form Dim ctl As Control Dim found As Boolean
'-------------------------------------------------------- ' 1. Try the active form first '-------------------------------------------------------- If Not Screen.ActiveForm Is Nothing Then Set frm = Screen.ActiveForm On Error Resume Next Set ctl = frm.Controls("StatusBox") On Error GoTo 0
If Not ctl Is Nothing Then found = True End If End If
'-------------------------------------------------------- ' 2. If not found, search all open forms '-------------------------------------------------------- If Not found Then Dim f As Form For Each f In Forms On Error Resume Next Set ctl = f.Controls("StatusBox") On Error GoTo 0
If Not ctl Is Nothing Then Set frm = f found = True Exit For End If Next f End If
'-------------------------------------------------------- ' 3. Update the control if found '-------------------------------------------------------- If found Then ctl.value = s & vbCrLf & Nz(ctl.value, "") DoEvents Else ' No StatusBox available ? fallback to MsgBox MsgBox CStr(s), vbInformation, "Status Message" End If
End sub at the end and then Public Sub Status(ByVal s As Variant) GlobalStatus s End Sub
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.