F. Michael Miller wrote:
I need to requery a subform from a third form and can't seem to get it to
work.
frmForm1 has frmAddress as a subform. The button cmdReviseAddress opens the
form frmUpdateAddress where all of my validation work is done and the new
record is added.
However, the new address is not being displayed in the subform.
If I use the command
Forms![frmTest]![frmAddress].Requery
it works fine.
The problem is that I want to be able to frmAddress on any form, and need to
pass the name of the main form (in this case frmForm1) as a variable.
If lsTemp = "frmForm1", the statement
Forms![lsTemp]![frmAddress].Requery (and every variation using brackets and
quotes that I can think of) fails.
Any ideas?
Thanks!
Forms(lsTemp)!frmAddress.Form.Requery should work.
You could drop the following code in a Module
Public Sub FormsRequery(strForm As String, _
Optional varSubForm As Variant)
If IsMissing(varSubForm) Then
Forms(strForm).Form.Requery
Else
Forms(strForm)(varSubForm).Form.Requery
End If
End Sub
This will requery a single form or a subform if you pass both main form
and sub form names.Ex:
FormsRequery "MainFormName"
or
FormsRequery "MainFormName","SubFormName"