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!

Subform behind in updating

Status
Not open for further replies.

Jonmit

Programmer
Aug 28, 2009
6
AU
My problem is a subform is updating one record behind what it should be. It concerns 2 forms/tables i am dealing with . The 1st form/table is for grain delivery records.2nd form/table is for grain sales.On the grain delivery form i have a button that opens the grain sales form to a new record and can enter sale details of that load of grain straight away. Also on the delivery form is a 'Sold' check box which marks it as sold and also the code i have been working with in previous discussion puts the 'grain sale' ID in a SaleID in the delivery form/table. After this happens i requery the 'grain sale' form as i have a condensed version of the delivery form as a subform there.When this event happens nothing changes, although i can see it requeries as the form flickers. If i enter another load for that grain sale then when it requeries the previous delivery record shows on subform etc etc. The subform on the 'grain sale' form is always one record behind. Even if i untick the check box to reverse the sale the subform is always one record behind? If i use the navigation buttons and go back one record on 'grain sale' form and then forward one record then the subform corrects itself. Is there another way of requerying, or something/event, to the 'grain sale' form, like the navigation buttons, to keep the subform in sinc with what i am doing?
Hope you can help
John
 
could you post your code?

M

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work
 
There are numerous ways to synchronize form/subform recordsets and you haven't indicated what approach you are using. But here are a couple of suggestions.

Open the Subform Control Properties, click on the Data tab and set the Link Child and Link Master Fields.

or presuming that the subform recordsource is a query that has a parent form based criteria [Forms]![ParentForm]!{SomeControlname], then requery the subform control on the parent form's OnCurrent event. This will fire whenever the parent form changes records.

Cheers, Bill
 
Thanks M and Bill for your replies.
M, i will post the code at the bottom. I finally got it sorted out and once again it was a reasonably simple thing but sometimes they seem to be the hardest to see.
Bill, i was using the Master/Child fields with the form that had the subform, but the Delivery form that i was checkmarking off was on a container form that held both the Main Sale form and Delivery form, with the Delivery form not linked to anything. I finally got it all to work by requerying the Delivery form first and then requerying the Sale subform after that. Probably a bit difficult to grasp when you are not the one actually putting it together.

Private Sub chkSell_AfterUpdate()
On Error GoTo Err_chkSell_AfterUpdate

Dim Msg, Style, Title, Response
Msg = "Yes = Leave as is. No = change to unsold."
Title = "Load has already been marked Sold"
Style = vbYesNo

If chkSell = -1 Then
txtSaleID = intGrainSaleNum
Me.Requery
Parent!frmGrainSalesInd!frmGrainSalesLoads.Requery
Else
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
chkSell = -1
Else
txtSaleID = Null
Me.Requery
Parent!frmGrainSalesInd!frmGrainSalesLoads.Requery
End If
End If
Exit_chkSell_AfterUpdate:
Exit Sub

Err_chkSell_AfterUpdate:
MsgBox Err.Description
Resume Exit_chkSell_AfterUpdate
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top