Setfocus to a textbox

G

Guest

Hi,

I have a form that has a textbox, subform, and a MSFlexGrid.

On Exit from the textbox I have code that adds the records to the flexgrid
after some processing, opening connections and recordsets to the DB.

At the end of the code the last thing the code does is to clear down the
textbox and sets the focus to it.

txtLPN.SetFocus
txtLPN.Text = ""
txtLPN.SetFocus

After the code executes the SetFocus method is called but the focus does not
set to the textbox.

I've also tried using DoCmd.GoToControl "txtLPN", but still the focus is not
on the textbox control.

Any ideas?
 
G

Guest

Hi Marcus

txtLPN.SetFocus
txtLPN.Text = ""

Should be

Me.txtLPN.SetFocus
Me.txtLPN =" "


Hope this helps
 
G

Guest

By adding 'Me', the same fault happens.

But I think its to do with a linked subform updating from a textbox after
the OnExit event has completed. Can't find an event for after the subform
updates, tried AfterUpdate but it does not trigger?
 
G

Guest

Hi

You did not mention a subform in your post ?

If you want to set the focus to a field on a subform from a main form you
have to do this in 2 stages.

1st set the focus to the sub form
2nd set the focus to the field

If you can let me know some details - where are you trying to "fire" the
event from. name of the main form, name of the sub form, etc. I can send
back the code.

I may have misunderstood but I think you are trying to do "something" on a
main form that will clear the details (check box) om a subform - hope this is
right.
 
G

Guest

What I have is the following:

FRM_ASN_HDR - Main Form
FRM_ASN_DET- Sub Form
txtCurrentASN - Textox on the Main Form
txtLPN - Textbox on the Main Form

What happens:

Input data into txtLPN

The data is confirm and updates the FlexGrid

This is done by the On_Exit Event from txtLPN.

The subform is linked to txtCurrentASN by Master/Child feilds. This is good
because as the value in txtCurrentASN changes the subform's data updates.

But, when the On_Exit event is triggered for txtLPNthe last bit of code is:

Me.txtLPN.SetFocus

But, the focus is returned to txtCurrentASN.

I've read an earlier post by yourself showing how to setfocus to a subform's
control, but this is not what i'm trying to do. I think that an event is
triggering after the On_Exit event of the textbox?
 
G

Guest

Hi

Just trying to get my head around this - as I can't see your form properties.

Can you let me know if this is right
You have a text box that you enter data (txtLPN) which is on your mai form
(FRM_ASN_HDR)

After you exit this text box you want to set the focus to a text box
(txtLPN) which is on a subform form (FRM_ASN_DET)

On getting the focus the text box (txtLPN) should clear ready to get some
new data.

Is this right ?

If it is what happen to the data this is already in txtLPN
 
G

Guest

Ive added a little bit of code to help, it seemed to work. What I do is the
following:

Clear the txtLPN:

txtLPN.SetFocus
txtLPN.Text = ""

SetFocus to txtCurrentASN

txtCurrentASN.SetFocus

SetFocus to txtLPN

txtLPN.SetFocus

BINGO - It worked, why, I don't know
 
G

Guest

I am gald you got it sorted out. Well done.

Just a point - if you write some code it is always worth spending a few
moments working why it works (or doesn't) as it is never a good idea to just
tap the keyboard and see what happens as 1 bit of code will sometimes affect
others. So well done again but have a look at the code you have written and
try and work it out.
 

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

Top