How to refer to a control on a child form in the on close event of the master fo

  • Thread starter graeme34 via AccessMonster.com
  • Start date
G

graeme34 via AccessMonster.com

Hi
Could anybody tell me how to refer to a control on a child form in the
master forms on close event?

I have the following code which updates underlying tables when the confirm
despatch entry form closes.
Private Sub Form_Close()
' On closing the confirm despatch form delete any records
' from the despatch line table that are = 0
' i.e. not goods sent this delivery and prevent repetitive
' records of 0 delivery

Dim rsDes As DAO.Recordset
Dim rsSal As DAO.Recordset
Dim strSQL As String
Dim lngDesNum As Long

strSQL = "SELECT tblDespatch.DespatchConfirmed ,tblDespatch." _
& "OrderComplete, tblDespatchLine.* " _
& " FROM tblDespatch INNER JOIN tblDespatchLine " _
& " ON tblDespatch.DespatchNumber = tblDespatchLine." _
& "[Despatch Number] WHERE tblDespatch.SalesOrderNumber = " _
& Me.SalesOrderNumber & " ORDER BY [Despatch Number] DESC;"

Set rsDes = CurrentDb.OpenRecordset(strSQL)

Set rsSal = CurrentDb.OpenRecordset("qryOutstandingSales", _
dbOpenDynaset)

lngDesNum = rsDes![Despatch Number]

If rsDes!DespatchConFirmed = False Then Exit Sub


Do While rsDes!SalesOrderNumber = Me!SalesOrderNumber And _
rsDes![Despatch Number] = lngDesNum

If rsDes![Quantity Sent] = 0 Then
rsSal.FindFirst "SalesOrderNumber = " _
& Me!SalesOrderNumber
Do While rsSal!SalesOrderNumber = Me!SalesOrderNumber
If rsSal![Product Code] = rsDes![Product Code] _
Then
rsSal!DespatchNotePrinted = False
Exit Do
End If
rsSal.MoveNext
Loop
rsDes.Edit
rsDes!OrderComplete = False
rsDes.Update
rsDes.Delete
End If

If rsDes![Quantity Sent] < Me.subfrmConfirmDespatch!txtOutstanding
Then

rsDes.Edit
rsDes!OrderComplete = False
rsDes.Update

End If

rsDes.MoveNext
If rsDes.EOF = True Then Exit Sub

Loop

End Sub

The problem seems to be Me.subfrmConfirmDespatch!txtOutstanding as this is
having a NULL value when debugging.
Any help would be greatly appreciated....
 
W

Wayne Morgan

I suspect that by the time you get to the main form's Close event, that the
subform is already closed or that at least it's recordset is closed. Try the
main form's Unload event. If that still isn't soon enough, try doing this in
the subform's Unload event (adjusting the syntax accordingly, of course).
The Unload event fires before the Close event.
 
G

graeme34 via AccessMonster.com

Thank you Wayne......Unload event worked fine.......Yet the On close event
still works on my works computer........would this be down to my home
computers processor being slow???
Thanks again will stick with unload in future.....

Wayne said:
I suspect that by the time you get to the main form's Close event, that the
subform is already closed or that at least it's recordset is closed. Try the
main form's Unload event. If that still isn't soon enough, try doing this in
the subform's Unload event (adjusting the syntax accordingly, of course).
The Unload event fires before the Close event.
Hi
Could anybody tell me how to refer to a control on a child form in the
[quoted text clipped - 68 lines]
having a NULL value when debugging.
Any help would be greatly appreciated....
 
W

Wayne Morgan

Since it is probably a timing issue, a different speed processor can
definitely make a difference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top