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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Go to new record in subform? 4

Status
Not open for further replies.

JSD

Technical User
Jan 18, 2002
189
US
Hello,

I am trying to go to a new record in a subform after update of a control on the main form. I had this in the OnEnter event of the subform:

DoCmd.GoToRecord , , acNewRec
DoCmd.GoToControl "basketno"

I tried putting this AfterUpdate of the control on the main form, adding the subform name:

DoCmd.GoToRecord ,Me.Child66 , acNewRec
DoCmd.GoToControl "basketno"

Neither works. basketno is the control I want to setfocus to once it has gone to the new record. Can someone help with a kick in the right direction?

Many Many Thanks

Jeremy



 
Jeremy
I have struggled with this same thing recently - moving to a control in a subform.

Given that the subform is actually a control on the main form, the first thing that has to happen is to move to that subform control, using...
Me.Form![YourSubformName].SetFocus
DoCmd.GoToRecord,,acNewRec

If the above doesn't take you to the right place in the subform, then add the following line of code...
Me.Form![YourSubformName]![basketno].SetFocus

It seems redundant to have to repeat some of this code but that's what I had to do.

At least this gives you something to try (hopefully a kick in the right direction.

Tom

 
[tt]
Hi:

Check the "tab order" of the main form. The name of the subform appears there. Put it next in order to the last control on the main form where you want to go to the sub. Then when you tab, the tab goes to the sub form, to the first control that you have enabled to receive a tab stop on that form. Obviously, you want to check the tab order on the sub form.

Works for me. I hope it's good for you.

Cheers,[tt]

[glasses][tt]Gus Brunston - Access2000(DAO)
Skill level based on 1-10: 7
Webmaster: www.rentdex.com[/tt]
 
[tt]
Ooops!

I didn't read your first post thoroughly enough.

After you get to the sub form, you want to go to a new record. Why not make the sub form "Data Entry"? You can handle which control gets the first shot with tab order.

However, if you want to show all existing records in the sub form before you enter a new record, set "Data Entry" to "No". Then the following code in the "On Open" event of the sub form ought to work:

Private Sub Form_Open(Cancel As Integer)
DoCmd.GoToRecord , , acNewRec
End Sub

HTH,[/tt]

[glasses][tt]Gus Brunston - Access2000(DAO)
Skill level based on 1-10: 7
Webmaster: www.rentdex.com[/tt]
 
[tt]
Hi:

I'm sorry to clutter up the airways, but the object is to get it right, right?

My sub forms I had in mind were all data entry. When I tried my own advice, it didn't work! The focus still went to the first control in the first record of the sub form. If I wanted the focus to go the first control of a new record, I had to enter code like this in the "On Enter" event of the control "basketno" in the sub form.

Private Sub basketno_Enter()
If Not IsNull(Me.basketno) Then
DoCmd.GoToRecord , , acNewRec
End If
End Sub

It's been good to chat like this.

Cheers,[/tt]

[glasses][tt]Gus Brunston - Access2000(DAO)
Skill level based on 1-10: 7
Webmaster: www.rentdex.com[/tt]
 
Before you can move to a control on a subform you have to first set the focus to the subform. As Tom says, it's redundant, but that's the way to get it done.
AvGuy
 
Hello Guys,

Thanks for the responses. Actually, the problem wasn't setting focus to the subform, because after user scans barcode value in the LAST control on the main form the only place left to go is the subform. I just had an issue with going to the new record in the subform (and still viewing the other records in the subform). However, I was going the wrong way; I was trying to use the code on the main form after update of the last control. Instead, I just put the GotoRecord on GotFocus of basketno (in the subform) and that worked. But I do like Gus's last approach with the Isnotnull function; think I'll use that in the future.

Thanks everybody for your time...Lord knows I don't deserve this much attention.

Jeremy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top