I am designing a db for users that use mice to navigate data entry forms (instead of tabbing through the controls). I am trying to find some code that I can use on an event procedure that will select all of the text in a form control when the user clicks in that control. So far I have failed.
The form I am working on will be used by data entry to enter multiple records. For example, they enter a project number, then enter the data on the subform. When done, they click in the project number field, hopefully all of the text in that field will be selected, they enter a new project number, and so on...
Nice Function CyberLynx, there are a couple enhancements I like to suggest.
1. Make the function Public for availability to any form. Just drop the 'Private' from 'Private Function', then put it in a public module, insted of the forms module.
2. You can define 'Ctrl' in the function as the ActiveControl and avoid having to pass the control name. This makes it more portable by not having to change the control name in the calling statement when using it on other control fields and forms.
Dim Ctrl As Control
Set Ctrl = Screen.ActiveControl
If Not IsNull(Ctrl) Then
Ctrl.SelStart = 0
Ctrl.SelLength = Len(Ctrl)
You can call a funtion by putting '=HighlightAll()' directly in the properties field of the control, mouse up or on click event.
Thank you CyberLynx. I was able to incorporate your suggestions into my forms with a little modification (primarily because the controls I am applying it to are combo boxes and the code seemed to select only a portion of the concatenated value that is displayed in the combo box). The fix was to specify the SelLength = 255. I hate to use the fixed value, but it works for now.
Thank you too bill for your suggestions. I would love to implement them so that I don't have to drop this code into every form that I create. I am having some troubles though. I created a module with the code that you suggested. Then, in the forms, I removed the function code and changed the On Mouse Up events to =HighlightAll() as you suggested. I receive an error message that access can't find the function name that I specified. I named my module HighlightAll. Perhaps I don't understand public modules enough to make this work. Any suggestions?
I understand the Public versus Private in the function code. What I am unclear on is where to place the code. In my limited experience, I have done all of my code in class modules for forms (I think that is the correct terminology), where I set event procedures.
Do Access databases have a general code module where I can put the function and have it accessible to all of my forms? Or, if I put it in one of my forms with the Public statement will it be accessible to other forms?
Look on the database window for the modules section, insert your common functions/ modules there. As time goes on put you can build libraries of such usefull functions and use in any / many Access projects.
The only downside is that the method of importing / sharing modules is cack handed. As far as I' aware, each time you change the library you have to reimport it.