Set Focus to an open form from a popup form (1 Viewer)

ukaquanaut

Registered User.
Local time
Today, 11:27
Joined
Feb 8, 2012
Messages
33
Hi Guys

I have a Form which has a datasheet subform, The user has a search as you type popup form to search stock items and find the code for one of the controls in the datasheet.

I have managed to get a double click to enter the stock code of the selected item into the subform data sheet control, but I cant manage to get the focus set back there so the user can tab onto teh next control in the datasheet.

I have tried a variety of form addressing, but I cant seem to progress with this.

I expect its a comon problem but I cant find a solution and have spent hours googling for it.

the address for the control that gets data inserted is:

' this inserts the value into the subform datasheet fine so the address of the control is ok
Forms!FrmSearchTest.Form!FrmSubSearchTest!StockCode = lstItems

Forms![FrmSearchTest]!FrmSubSearchTest.SetFocus
Forms![FrmSearchTest]!FrmSubSearchTest.Form!StockCode.SetFocus

I managed to get these two lines to run as in no errors(it doesnt crash out), but it doesnt change the focus at all.

Any thoughts would be appreciated.

Jerry
 
Last edited:

vbaInet

AWF VIP
Local time
Today, 19:27
Joined
Jan 22, 2010
Messages
26,374
Is StockCode the name of the field or the name of the control?
 

ukaquanaut

Registered User.
Local time
Today, 11:27
Joined
Feb 8, 2012
Messages
33
Is StockCode the name of the field or the name of the control?

Hi I always find the difference hard to get to grips with. I thought fields were in tables and controls were on forms.. but as I said I never got that straight.

Its the box on the form that the data goes in and ultimately gets put into an underlying table.

Many Thanks for looking at this

Jerry
 

Kiwiman

Registered User
Local time
Today, 19:27
Joined
Apr 27, 2008
Messages
799
Howzit

When you drag a field from your field list onto a form you will find that the Name of the control and the Control Source are the same value as the field name. However there is nothing to stop a user from renaming that control name.

When you add a control from the tool box this will have a generic name like Combo1, text1 etc which you can then name to be more relevant and meaningful

When referencing controls in vba you need the control name which is on the Form Properties >> Other tab >> Name. It is often this distinction between fieldname and control name that gets confused, which is why VBAINET asked the question.
 

ukaquanaut

Registered User.
Local time
Today, 11:27
Joined
Feb 8, 2012
Messages
33
Hi Thanks for the class in objectnames.

I did manage to find the solution which I thought I would post here incase anyone else comes across this issue regardless of your access literacy level.

' Set the focus to the object you want to return to
Forms![FrmSuppliedDrugs]!FrmSubIncomingDrugs.SetFocus
Forms![FrmSuppliedDrugs]!FrmSubIncomingDrugs.Form!StockCode.SetFocus

' Change the selected object to the form with the focus...
DoCmd.SelectObject acForm, "FrmYourName"

I hope that helps a little

Jerry
 

Users who are viewing this thread

Top Bottom