Set focus

bknight
BronzeLounger
Posts: 1389
Joined: 08 Jul 2016, 18:53

Set focus

Post by bknight »

In a code outside of a form how does one set focus on a particular field of a form?

Code: Select all

Forms!frmTrades.Profit???

bknight
BronzeLounger
Posts: 1389
Joined: 08 Jul 2016, 18:53

Re: Set focus

Post by bknight »

Never mind I tried a few statements and came up with

Code: Select all

forms!frmTrades.Profit.SetFocus

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Set focus

Post by HansV »

If that form doesn't have the focus yet, you have to use

Code: Select all

Forms!frmTrades.SetFocus
Forms!frmTrades.Profit.SetFocus
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1389
Joined: 08 Jul 2016, 18:53

Re: Set focus

Post by bknight »

I haven't tied your suggestion yet as I am in the process of debugging code, but when I used the solution I posted focus is indeed in/on profit. However the only way that I have discovered to get it out of focus is to place the cursor in a field of a new record, both enter and tab do nothing.
Will your suggestion leave the record where enter or tab works?

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Set focus

Post by HansV »

That depends on what has focus inside the form.
Best wishes,
Hans

bknight
BronzeLounger
Posts: 1389
Joined: 08 Jul 2016, 18:53

Re: Set focus

Post by bknight »

HansV wrote:
30 Apr 2023, 19:55
That depends on what has focus inside the form.
How would I check to see if that were the case?

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Set focus

Post by HansV »

You are the one in control of the database, not I...
Best wishes,
Hans