GoToRecord acNew in a Subform

  • Thread starter BFish via AccessMonster.com
  • Start date
B

BFish via AccessMonster.com

I have set a main form to lookup a record and when found checks for two
values in that record from controls. If true then setting focus to linked
subform to add an invoice set to acNew. If false I need the focus set back
to the main form controls (which all is currently working) for correct user
input, but still set the subform to acNew. This form stays open until all
main form records are entered or updated, so I need this to occur for
everytime a lookup is performed. Additionally the subform's record source is
a table. I am having trouble in setting the object in the DoCmd.GoToRecord, ?
?????,acNew and/or placement in the code.

Private Sub Combo40_AfterUpdate()
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[BusinessInformationID] = " & Str(Nz(Me![Combo40], 0))
Me.Bookmark = rs.Bookmark

If Not IsNull([BUSINESS NAME]) Then
If CodingID = 1137468902 Or IsNull(CodingID) Or PayCodeID = 0 Or
IsNull(PayCodeID) Then
If CodingID <> 1137468902 And PayCodeID = 0 Or IsNull
(PayCodeID) Then
PayCodeID.SetFocus
Else
CodingID.SetFocus
End If
Else
Me![Invoice Entry].SetFocus
Me![Invoice Entry].Form![Invoice Number].SetFocus
DoCmd.GoToRecord , , acNewRec

End If

End If
rs.Close
End Sub

As is now will go to the new record on the subform when IF statements are
False, I think proper placement is after the last End If but having trouble
referencing the form or table to go to the new record with setting focus.
Can anyone help!

Thanks,

Bill Fischer
 
K

Ken Snell \(MVP\)

Easiest way to move a subform to a new record is this:

Me.SubformName.Form.Recordset.AddNew

where SubformName is the name of the subform control (the control that holds
the subform object).
 
B

BFish via AccessMonster.com

Thanks Ken,

Your quick response is the drug that cured the ill. I see I was heading in
the wrong direction with attempts of DoCmd.

Me.SubformName.Form.Recordset.AddNew worked just like you said "easiest".

Bill Fischer
Easiest way to move a subform to a new record is this:

Me.SubformName.Form.Recordset.AddNew

where SubformName is the name of the subform control (the control that holds
the subform object).
I have set a main form to lookup a record and when found checks for two
values in that record from controls. If true then setting focus to linked
[quoted text clipped - 47 lines]
Bill Fischer
 

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

Similar Threads


Top