Solved Move to subform control after update errors (1 Viewer)

hullstorage

Registered User.
Local time
Today, 20:37
Joined
Jul 18, 2007
Messages
213
Hi all, a bit rusty as not used access in a while but decided to create new database so getting back to grips lol

anyway i have form called goodsinward and subform goodsinwarddetails

how do i move from field in form (after update) to field in subform ?

Ive tried these but getting error

Forms!GoodsInwardDetails_Subform.SetFocus
Forms!GoodsInwardDetails_Subform.Form!SuNumber.SetFocus
also tried

Forms!GoodsInwardDetails.SetFocus
Forms!GoodsInwardDetails.Form!SuNumber.SetFocus

also tried
Me!GoodsInwardDetails.SetFocus
Me!GoodsInwardDetails!SuNumber.SetFocus
 

Minty

AWF VIP
Local time
Today, 20:37
Joined
Jul 26, 2013
Messages
10,375
Set focus to the subform container control first, then set focus to the control you want on the subform.

Personally, I would use the Me.SubformControl.SetFocus syntax if I was in the form itself.
 

hullstorage

Registered User.
Local time
Today, 20:37
Joined
Jul 18, 2007
Messages
213
so the subform is called "GoodsInwardDetails" and the field is called "SUNumber", how do i name these in focus?
is it GoodsInwardDetails_Subform or just GoodsINwardDetails?

Thanks
 

Edgar_

Active member
Local time
Today, 14:37
Joined
Jul 8, 2023
Messages
438
so the subform is called "GoodsInwardDetails" and the field is called "SUNumber", how do i name these in focus?
is it GoodsInwardDetails_Subform or just GoodsINwardDetails?

Thanks
If the name of the subform control (not the name of the form that it's holding) is GoodsInwardDetails, then:
Forms.GoodsInward.Form.GoodsInwardDetails.SetFocus
Forms.GoodsInward.Form.GoodsInwardDetails.Form.SUNumber.SetFocus
Or
Forms!GoodsInward.Form!GoodsInwardDetails.SetFocus
Forms!GoodsInward.Form!GoodsInwardDetails.Form!SUNumber.SetFocus
Or
Forms.Item("GoodsInward").Form.Controls.Item("GoodsInwardDetails").SetFocus
Forms.Item("GoodsInward").Form.Controls.Item("GoodsInwardDetails").Form.Controls.Item("SUNumber").SetFocus

If the subform control is named GoodsInwardDetails_Subform, then:
Forms.GoodsInward.Form.GoodsInwardDetails_Subform.SetFocus
Forms.GoodsInward.Form.GoodsInwardDetails_Subform.Form.SUNumber.SetFocus
Or
Forms!GoodsInward.Form!GoodsInwardDetails_Subform.SetFocus
Forms!GoodsInward.Form!GoodsInwardDetails_Subform.Form!SUNumber.SetFocus
Or
Forms.Item("GoodsInward").Form.Controls.Item("GoodsInwardDetails_Subform").SetFocus
Forms.Item("GoodsInward").Form.Controls.Item("GoodsInwardDetails_Subform").Form.Controls.Item("SUNumber").SetFocus

All of these are to be used from outside your main form, but can work from inside your main form as well. However, if you're gonna reference the subform from the main form, then use Me instead of Forms.FormName for simplicity. Should I post the Me variations?
 
Last edited:

hullstorage

Registered User.
Local time
Today, 20:37
Joined
Jul 18, 2007
Messages
213
still getting errors, ive renamed subform to GoodsInwardDetails and also attached copy of mockup if you would be so good to see whats wrong with it please
 

Attachments

  • Rico2023.zip
    108.7 KB · Views: 56

hullstorage

Registered User.
Local time
Today, 20:37
Joined
Jul 18, 2007
Messages
213
yes i do but seems coding seems to have changed since i last used it on access 2013 😂😂
 

Minty

AWF VIP
Local time
Today, 20:37
Joined
Jul 26, 2013
Messages
10,375
I renamed your subform control to contGoodsInwardDetails (e.g.the subform container), not the subform itself.
Then this works:
Code:
Private Sub RMA_NUMBER_AfterUpdate()

  Me.contGoodsInwardDetails.SetFocus
  Me.contGoodsInwardDetails.Form.SUNumber.SetFocus

End Sub
 

Attachments

  • Rico2023.zip
    108.9 KB · Views: 57

CJ_London

Super Moderator
Staff member
Local time
Today, 20:37
Joined
Feb 19, 2013
Messages
16,674
ive renamed subform to GoodsInwardDetails
no, you haven't

1. suggest remove spaces for field and control names - it only adds confusion to what you need to use (square brackets or underlines)
2. coding has not changed

this works for me in your example app

GoodsInwardDetails_Subform.Form.SetFocus
GoodsInwardDetails_Subform.Form.SUNumber.SetFocus
 

hullstorage

Registered User.
Local time
Today, 20:37
Joined
Jul 18, 2007
Messages
213
no, you haven't

1. suggest remove spaces for field and control names - it only adds confusion to what you need to use (square brackets or underlines)
2. coding has not changed

this works for me in your example app

GoodsInwardDetails_Subform.Form.SetFocus
GoodsInwardDetails_Subform.Form.SUNumber.SetFocus
AHHH great thanks, i didnt even think of the nameing in the fields section.. cheers.. i did say i was rusty lol
 

Edgar_

Active member
Local time
Today, 14:37
Joined
Jul 8, 2023
Messages
438
Marked as solved, but to further clarify. You mentioned the subform control name had an underscore like GoodsInwardDetails_Subform, but it was actually a space, like GoodsInwardDetails Subform.

There was also an incorrectly copy-pasted instruction that was duplicated in the sample.

But this is the code that would have worked without changing control names, so you still have this option.
Code:
Private Sub RMA_NUMBER_AfterUpdate()
    Forms!GoodsInward.Form![GoodsInwardDetails Subform].SetFocus
    Forms!GoodsInward.Form![GoodsInwardDetails Subform].Form!SUNumber.SetFocus
End Sub
 

Users who are viewing this thread

Top Bottom