Refresh form

  • Thread starter Thread starter Gary
  • Start date Start date
G

Gary

I have a form and subform. The subform is based on a
parameter query. I add records to the underlying table
that the parameter query is based on and I want to show
the new records in my subform. I am using the requery
method of the subform but I do not see the new records,
in the subform, that were added until I move to the next
record and back to the record that was changed. Need to
know how to get the subform to requery without moving off
the record. Here is my code. Thanks.

Private Sub cmdAddCategory_Click()
Dim varBookmark As Variant

varBookmark = Forms![frmCustomerEdit].Bookmark
DoCmd.OpenForm "frmSelectCategory"
Forms![frmCustomerEdit]![qryCustomerCategoryData
subform3].Requery
Forms![frmCustomerEdit].Bookmark = varBookmark
End Sub
 
Hi Gary,
I'll not sure if this is the problem. But Access does not
save a record (or changes) till you move to another record
or close the object (table, query or form).

Use the line:
RunCommand acCmdSaveRecord

luck
Jonathan
 
Gary said:
I have a form and subform. The subform is based on a
parameter query. I add records to the underlying table
that the parameter query is based on and I want to show
the new records in my subform. I am using the requery
method of the subform but I do not see the new records,
in the subform, that were added until I move to the next
record and back to the record that was changed. Need to
know how to get the subform to requery without moving off
the record. Here is my code. Thanks.

Private Sub cmdAddCategory_Click()
Dim varBookmark As Variant

varBookmark = Forms![frmCustomerEdit].Bookmark
DoCmd.OpenForm "frmSelectCategory"
Forms![frmCustomerEdit]![qryCustomerCategoryData
subform3].Requery
Forms![frmCustomerEdit].Bookmark = varBookmark
End Sub

First, is the command button cmdAddCategory on form frmCustomerEdit? If
so, we can replace all those "Forms![frmCustomerEdit]" references with
the keyword "Me". For the moment, I'll assume this is so.

Second, it looks as though you're getting and then restoring a bookmark
from the main form, not from the subform. But this won't work even if
you did it with the subform, because when you requery you've got a new
recordset, and the bookmark of that recordset wouldn't be compatible.
Instead, you need to save the value of the primary key of the current
subform record, and then find that record again. Something like this:

Dim varID As Variant

With Me![qryCustomerCategoryData subform3].Form
varID = !ID
DoCmd.OpenForm "frmSelectCategory"
.Requery
.Recordset.FindFirst "ID=" & varID
End With

That's assuming that the primark key field is "ID" and that it's a
numeric field.
 
Back
Top