Setting Cursor Location in Textbox

G

Guest

Is there a function that would allow me to set the cursor at a specific
offset in a textbox?

Reason: I wish to use a textbox to search for a record, i.e., when the user
types the first character of the primary key in the textbox, On_Key event
will fire, do a search, then fill in the form with the first record found.
This will include the records's primary key with the cursor set after the key
typed. Continued typing of more characters will result in the search being
narrowed until the right record is displayed. After each character is typed,
the cursor will be located after that last character.

John H W
 
G

Guest

No. Instead of using the "Find" popup window, I want to type in the "search"
primary key and have the record found to display with the cursor set in the
textbox as the location corresponding to the number of keystrokes (or less if
the backspace is hit). If the Enter or Tab key is hit or lose focus, then
that is the record I want to work on.
Example:
First keystroke of 1 that finds a record with the following primary key
12345678 would have displayed: 1I2345678 where the I is the cursor.
Second keystroke of 5 would find a record of 15324 would have displayed
15I324, etc.
Of course, the I would be the cursor. Does that explain what I need?

John H W
 
G

Guest

Klatuu: I thought about using a separate textbox, but I wanted to be able to
use the "search" primary key in the event that a record is not found without
the user having to retype it. When I programmed a database back in the DOS
days (in C), I found that this type of forward thinking very well received.

Speed is a consideration, and I have test this by keeping track of what had
been typed in, in a separate variable, then "overwriting" the returned
record's primary key with what had been typed in. This causes the "not
saved" record event to fire and if the user does not exit the textbos
gracefully (tabs, etc.), saves what had been typed back to the database. So
I figured that just placing the actual primary key into the textbox with the
cursor showing what had been "searched" would be better.

John H W
 
G

Guest

I understand why you want to do what you are after, but it appears it will be
problematic. Trying to do what you are after is beyond my experience.
Good luck. I would like to know how it turns out.
 
G

Guest

John,

No offset is necessary. Just use the Change event to look for the record.
Present the result in a separate text box or list. Each time you enter a
character, the search will execute and present the new result.

A word of cauton:
Depending on how large your table is, speed of the network, etc. Each
search can take some time. This pause between keystrokes can confuse and
irritate users.
 
K

Ken Snell [MVP]

Not sure that I'm understanding exactly, but you can manipulate the position
of the cursor in a control by using the control's SelStart property. Check
it out in VBA Help files, and post back if you have questions.
 

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