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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

requery a subform

Status
Not open for further replies.

golfnooch

Instructor
Aug 8, 2001
6
US
i have a main form that is based on a query, with a subform that is also based on a query...how do i requery the subform when a value changes in the main form without requerying the main form?
 
You should be able to do it very easily. Go into your event handler code for when you want this to happen and paste the following code. (For example if you want to to requry after 'Text1' is updated. Right click on 'Text1'. Click the event tab. On the after update line type "[Event Procedure]". Click on the three dot button and paste your code between the private sub line and the end sub line) If your subform is named something other than child0 then replace child0 with the name of your subform
Code:
Child0.Requery
The hardest questions always have the easiest answers.
 
Hi!

Write subform requery command in the procedure Form_AfterUpdate of main form. It will be excellent that user don't espy this action. You can write following codes in the procedure Form_AfterUpdate of main form:

Private Sub Form_AfterUpdate()
Dim varFieldID 'Variant type variable
Dim rst As Recordset

'Value of unique field of current record for bookmarking
varFieldID= Me.MySubForm.Form!FieldID
'Requery the subform
Me.MySubForm.Form.requery
'Find previouse subform's record (before requery)
rst.FindFirst "FileID=" & varFieldID 'Use necessary separators for different field types
If Not rst.NoMatch Then 'If found
Me.MySubForm.Form.Bookmark = rst.Bookmark
End If
rst.Close
Set rst = Nothing
End Sub


Aivars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top