current record not available after add

  • Thread starter Thread starter Daniel Wilson
  • Start date Start date
D

Daniel Wilson

I have a form ("Sales") with several subforms. One of the subforms,
"Purchaser", is tied to the Sale record by a Purchaser ID in the Sale
record.

When I enter the Purchaser subform, I have some code to add a new
purchaser record if the Purchaser ID in the Sale record is NULL or 0.

The problem comes when I've just added a Sale from the Sales form using
the Add (rightmost) button of the record navigator. When I enter the
Purchaser subform, the current record is the one before the add. At
least, the Purchaser ID and the Sale ID are reported that way.

Private Sub Purchaser_Enter()
Dim lNew As Long
'On Error Resume Next

'Line below shows Purchaser from record before add!
'*****************vvvvvvvvvvv*********************
If IsNull(Me.Recordset!Purchaser) Or Me.Recordset!Purchaser = 0 Then
lNew = AddCustomer()
Me.Recordset.Edit
Me.Recordset!Purchaser = lNew
Me.Recordset.Update

Purchaser.Requery

CurrentCustID = lNew
End If
End Sub

What am I doing wrong?

Thanks.

Daniel Wilson
 
Here's my solution in case it helps anyone else. Basically, if the
record was just added, we force a Purchaser_Exit before allowing
edition in the Purchaser subform.

Private Sub Form_AfterInsert()
mbJustAdded = True
End Sub

Private Sub Purchaser_Exit(Cancel As Integer)
On Error Resume Next
Me.Recordset.Edit
Me.Recordset!Purchaser = Purchaser.Controls.Item("ID_text").Value
Me.Recordset.Update
CurrentCustID = Me.Recordset!Purchaser
End Sub

Private Sub Purchaser_Enter()
Dim lNew As Long
Dim bDummy As Boolean
On Error Resume Next

If mbJustAdded Then
mbJustAdded = False 'No recursion, please!!!
txtSaleAccount.SetFocus
Purchaser.SetFocus
End If

If IsNull(Me.Recordset!Purchaser) Or Me.Recordset!Purchaser = 0
Then
lNew = AddCustomer()
Me.Recordset.Edit
Me.Recordset!Purchaser = lNew
Me.Recordset.Update

Purchaser.Requery

CurrentCustID = lNew
End If

mbJustAdded = False
End Sub


hth someone

Daniel Wilson
WilliamstonConsulting at GMAIL dot com
 
Back
Top