Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hidden Subforms -- Clearing 1

Status
Not open for further replies.

oraclejunior

Technical User
Jul 8, 2003
111
0
0
GB
I have a number of hidden forms in a main form.
I can create records, update records and recalc forms so that all combos are current when I make eacj form visible. But how do I clear the contents of the form each time it becomes visible.

Thanks
 
How are ya oraclejunior . . .

Have a look at the [blue]Data Entry[/blue] property of the form . . .

Calvin.gif
See Ya! . . . . . .
 
Have looked at data entry it was set to yes, I set it to no selected another form, came back to the changed form and data was there.

(please note these are unbound forms).
 
oraclejunior said:
[blue]. . . (please note these are unbound forms) . . .[/blue]
That makes things even easier! . . .
[ol][li]In the [blue]Tag[/blue] property of each textbox on each subform you want to clear, enter a question mark [blue]?[/blue][/li]
[li]Copy/paste the following routine to a module in the modules window:
Code:
[blue]Public Sub clrSubForm(SubFrmName As String)
   Dim frm As Form, ctl As Control
   Set frm = Forms![purple][b]MainFormName[/b][/purple](SubFrmName).Form
   
   For Each ctl In frm.Controls
      If ctl.Tag = "?" Then ctl = Null
   Next
   
   Set frm = Nothing
   
End Sub[/blue]
[/li][/ol]
Whenever you want to clear a subform, call the routine:
Code:
[blue]   call clrSubForm([purple][b]subFormName[/b][/purple])[/blue]

[blue]Your Thoughts! . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
I see what the code is doing but when run it brings up a type mismatch error?
 
Roger That oraclejunior . . .

Its also not universal like I intended and I forgot double quotes around the subformName.

Replace the code with the following:
Code:
[blue]Public Sub clrSubForm(MainFormName As String, subFormName As String)
   Dim frm As Form, ctl As Control
   Set frm = Forms(MainFormName)(subFormName).Form
   
   For Each ctl In frm.Controls
      If ctl.Tag = "?" Then ctl = Null
   Next
   
   Set frm = Nothing
   
End Sub[/blue]
The call becomes:
Code:
[blue]   Call clrSubForm("[purple][b]MainFormName[/b][/purple]", "[purple][b]subFormName[/b][/purple]")[/blue]

Calvin.gif
See Ya! . . . . . .
 
Superb, that worked a treat.

Thank you, I can apply this to all forms that need to be cleared when they become visible.
 
oraclejunior . . .

Be aware: although a form is not visible to the eye [blue]you can still manipulate it with VBA![/blue] . . . for instance clear the the subform before making it visible . . . assign values, ect . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top