Full Version: Question About Form With About 200 Text Boxes
UtterAccess Forums > Microsoft® Access > Access Forms
Each box contains a character in it that when the textbox is clicked will be added to the string in the main text box at the top of the form.
Is there an easier way to write the vba code or do I need an OnClick event for each of the textboxes?
Doug Steele
Create a generic function (not a sub) along the lines of:
Function AddLetter()
  Me!NameOfMainTextBox = Me!NameOfMainTextBox & Screen.ActiveControl.Value
End Function

(replace NameOfMainTextBox with the actual name...)
Set the On Click property to =AddLetter() for each of the 200 text boxes (include the equal sign and parentheses). Note that you can set the property for multiple text boxes at once. Select them (lasso them, click one after the other while holding the shift key, use the cursor at the top or side of the form). Whatever you type into the Properties dialog will apply to all of the selected controls. You can also set the On Click property through code. If, for instance, your text boxes are name Text1 through Text200, you could use:
Dim lngLoop As Long
  For lngLoop = 1 to 200
    Me.Controls("Text" & lngLoop).OnClick = "=AddLetter()"
  Next lngLoop
Awesome! Thank you very much!
I'm getting an error.
problem occurred while TestDatabase was communicating with the OLE server or Active X control
I'm tried a few things, use a macro to call the function, put an onClick event on one of the boxes to call the function. and I keep getting that error.
Any suggestions?
Doug Steele
What's the exact code of your function?
Are you certain you're only calling it from the text boxes in question?
Have you compacted the database?
I had compacted the DB, but that didn't help so I copied all the boxes onto a new form and everything works fine now. Thanks!
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.