I have a form that contains a Form_Keydown subroutine and a textbox.
I am using a bluetooth numeric pad for input, so there is no mouse involved.
The first keypress should display the contents of a corresponding array contents (e.g. pressing 4 should display the array's fourth element).
The textbox should then be activated to allow the array's contents to be changed.
The form should then be closed by pressing the Enter key (or decimal point key).
Sounds simple.
However, as soon as the form is opened, the focus moves to the textbox and the Keydown sub is ignored.
Hitting the keypad's buttons enter numbers into the textbox, without the opportunity to display the existing array's contents.
Is there a way of removing focus from the textbox until after the first key is pressed?
Also, how do I move to another form after entering numeric input to the textbox?
Thanks

Change the tab index to another control, for instance a command button. The reason the textbox gets focus on your form load event is because the tab index is set to 0. When a form loads, it will always pass the focus to the first control in a form where the index is zero.

Thanks AndreRet
The only problem is that the textbox is the only control on the form!
The page is meant to be used remotely, using just the bluetooth numeric keypad.
As a test, I added a command button, made it tab index 0 and the textbox tabindex 1.
However, the focus then remains on the button and it still ignores the keypresses.
I can't think of a way to first accept a single keypress, then switch to the textbox for data entry.
Thanks again

I would add a command button, make it visible but hide it outside the parameters of your form. in other words, outside the form the user can not see. It will still get the focus.

Now call your sub and then make the command button visible property false.

AndreRet,
Great, that works!
The form allows keypad entry - then I use a line in a subroutine to make the textbox visible, thus allowing text entry.
I have set the maximum number of digits to 3.
But how do I get the textbox to lose focus again after I enter three digits?
This would allow me to use a keypress to leave the form.

just make the textbox visible property false, it will loose focus automatically.

if this solves your problem, please mark it as solved found at the bottom of this page.:)

It works!
Thanks a lot for your assistance.

Only a pleasure. Happy coding!:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.