PDA

View Full Version : Wild card form close



Trevor
03-14-2008, 10:27 PM
I would like to use a wild card statemene to close any form with "help" in the caption of the form:
I have tried to no avail :

If Len ( * &"Help") >=1 Then DoCmd.Close

Note: their could be 1 - 3 words before the word "help" in the form caption

Carl A
03-15-2008, 03:52 PM
If InStr(1, Me.Caption, "Help", vbTextCompare) Then DoCmd.Close

Trevor
03-15-2008, 06:00 PM
that didn't work at all, I tried placing it on my exit form button, witch will close the form, and I would at that time also want to close any forms with the word "help " in the caption and the form with "help" in the caption stayed open

DarkSprout
03-15-2008, 06:29 PM
This should do the trick:
Place the Function in a public module,and call it when ever you wish to close them.
Public Function CloseHelpForms()
'// DarkSprout March08
Dim x As Integer

For x = 0 To Forms.count - 1
'If InStr(1, Forms(x).Name, "Help", vbTextCompare) > 0 Then ' <- use to search for help in form name
If InStr(1, Forms(x).Caption, "Help", vbTextCompare) > 0 Then ' <- use to search for help in form caption
DoCmd.Close acForm, Forms(x).Name, acSaveNo
End If
Next
End Function