VisualBasic for Applications

AtlantaBob

Golden Member
Jun 16, 2004
1,034
0
0
Two quick questions, of course, answers can't be found in Microsoft Help.

In VBA (host app is Access 2003), how do I automatically move the cursor to the end of a memo field when a form opens? As it is, all of the text is selected when the form opens, and I don't want someone to easily overwrite the text if they're not paying attention.

Also, how do I automatically select all of the text in a combo box whenever the user clicks inside the text box component?

I realize it will be an oncick or onfocus event (or something of the sort), but how could I write the code to select everything -- or just clear the contents entirely? (onclick, then set the variable of the combobox to "" ? I'll try that, but I'd rather just select all of the text, so someone could click again and edit the text if the needed to.

Thanks in advance.
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
To move the cursor to the end of the memo field:
In the form Load event add code like

Me.txtbox.SelStart = Len(Me.txtbox.Text)

For number two in the onfocus event add something like
Me.txtbox.SelStart = 0
Me.txtbox.SelLength = Len(Me.txtbox.Text)