It is common practice to use a standard module where you want to do the same
thing on different forms.
Just pass in a reference to the form, and then use that variable instead of
the "Me" keyword.
This example is designed for forms where you use unbound controls in the
Form Header to build a filter, and you need a command button to remove the
filter and clear all the unbound controls in the form header. The button's
On Click event would be set to:
=ClearFilterAndHeader([Form])
and you can copy the button to other forms.
Public Function ClearFilterAndHeader(frm As Form)
If HasProperty(frm, "Dirty") Then
If frm.Dirty Then 'Save if necessary.
frm.Dirty = False
End If
frm.FilterOn = False
frm.Filter = vbNullString
End If
'Clear all the unbound controls in the form header.
For Each ctl In frm.Section(acHeader).Controls
If HasProperty(ctl, "ControlSource") Then
If Len(Nz(ctl.ControlSource, vbNullString)) = 0& Then
If Not IsNull(ctl.Value) Then
ctl.Value = Null
End If
End If
End If
Next
End Function
Public Function HasProperty(obj As Object, strPropName As String) As Boolean
On Error Resume Next
vardummy = obj.Properties(strPropName)
HasProperty = (Err.Number = 0)
End Function
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Maaike said:
I'm creating a database-application in which I want to reuse some subs. I
want to do this by using a standard module (a new module). Is it possible to
change the values of components (e.g. textboxes) in this module or is this
only possible in a class module?