Trouble with SetFocus

Sess

Registered User.
Local time
Yesterday, 23:22
Joined
Jan 4, 2010
Messages
74
I have tried to search this out but have found conflicting suggestions and still have not found a solution.
I have a form with two fields, one a ComboBox and the other a text box, both are unbound and two controls, one is to close the form the other is to close the application .
On entering the the combo box is the first tab stop which I need because an item is to be selected from the pulldown, next the end user scans a barcode. The barcode reader is set to folow input with CHR$13 CHR$10 to emulate striking the Enter key on the keyboard. This is to be the trigger for an SQL based on the COmbo value and the scanned data to update a database.
All of that works EXCEPT after testing the data or running the SQL I would like the focus to be placed on the text box, so I placed a Me.Text1.SetFocus after my EndIf so irregardless of the result of the testing it will place the cursor into Text1. It does not and I am perplexed to how to get this to function.
Any and all help would be appreciated.
 
Try < Docmd.Gotocontrol ("control_name") > instead of me.control_name.setfocus

Note that you cannot send the focus to another control if you have a Lost_Focus event procedure also for that control since you give vba then a potential conflict (for e.g. if you tried to send the control somewhere else on Lost_Focus event)
 
I just tried it and it still sets focus to the combobox and not the textbox. I tried
DoCmd.GoToControl ("Text5")
DoCmd.GoToControl "Text5"
I have been trying to run the whole code in both AfterUpdate and OnExit events. Everything else works except placing the focus back to the textbox.
 
What's the error message ?
(you said text1 not text5 ??)

If you are not geeting an error are you sure you are actually running through the setting focus code? You can check by sticking docmd.beep in just before - just a thought, I often miss code when I'm using lots of If statements and dont realise I am exit subbing and so never get to the end!
 
ooooops - yes it is Text5 and not Text1 as I first said. I actually copy and pasted from my VB the second time so that is really the real text box name.
I am not getting any error message at all and I tried debugging by stepping through the entire code in case there is somewhere that it takes a shortcut out of the code somehow but it steps through as if it will return me to Text5 but instead it takes me to the Combobox.
I just ran it with the DoCmd.Beep before my setfocus and it did include the Beep, so I placed it after my setfocus and it again included the Beep.
 
Thanks for all your help but I have changed strategy.
Just gave it some deep thinking and decided that if there is only one text box that the end user needs to go back to I will make it a one and only text box in a subform. Now it works because there is only one place that focus will set to by default.
When a user open the screen now there is the combobox that gets focus first then the subform is second in tab list so the cursor jumps there and by default to my text box and after the UPC scan it returns to the box by default.
Anyhow, thank you for the help because you taught me two handy codes that I did not know about, specially DoCmd.Beep, that will be very handy.
 

Users who are viewing this thread

Back
Top Bottom