PDA

View Full Version : Typing Too Fast Causes Problems With TextBox



Wamiv
01-24-2018, 12:14 PM
I'm trying to switch a TextBox_Change() to a TextBox_LostFocus event. The reason I'm doing this is because in the textbox I have to enter long strings and for some reason if you type quickly word will select the entire textbox and overwrite it while typing (Word 2007). Doing a direct switch from Change to LostFocus is causing a crash and I think it is because I am copying the ActiveX TextBox value to a Legacy FormField but I am not sure (I am very much a VBA newbie). Anyways my code looks like this



Private Sub TextBox_Change()
ActiveDocument.FormFields("FF1").Result = TextBox.Value
End Sub


Using this code I get the quick type overwrite the text box issue. When I switch the Change to LostFocus it causes word to experience an unrecoverable crash. I'm sure what I'm doing wrong is really simple but I can't figure it out.

SamT
01-24-2018, 02:50 PM
Interesting. Your LostFocus code fails, so you give us the (working) Change code.

Wamiv
01-25-2018, 06:08 AM
[code]
Private Sub TextBox_LostFocus()
ActiveDocument.FormFields("FF1").Result = TextBox.Value
End Sub
[\code]

Here is the non-working code. Although I would hesitate to call the Change code as working due to the issue I'm having where typing in the field too quickly will cause the typing to overwrite the field. Basically I have 2 problems and I'm looking to fix either one. Either make it so rapid typing doesn't overwrite the field or get the lostfocus sub to work to try to avoid whatever is causing the textbox to get selected (I've tried without the change sub in place and the textbox will not get overwritten unless the change sub is active).

SamT
01-25-2018, 08:07 AM
the issue I'm having where typing in the field too quickly will cause the typing to overwrite the field.
I'll change the thread Title to reflect that.

It appears you're using an Ole Object, which are the only controls with a LostFocus Event. I'm not that familiar with them.

I generally use the Exit Event to trigger code after entering text in a UserForm control.

Wamiv
01-25-2018, 08:21 AM
Do exit events work with ActiveX TextBox within word? I tried that and also could not get it to function. Under the dropdown for available events there doesn't appear to be an exit event either. Sorry for the basic questions, I'm a chemist who's been tasked with getting a simpler solution to people constantly filling in forms wrong so I'm learning VBA as I go.

SamT
01-25-2018, 09:08 AM
I'm a chemist who's been tasked with getting a simpler solution to people constantly filling in forms wrong

I recommend closing this thread and starting a new one based on that premise. IOW, Automating Data Entry Forms, Design and Best Practices. I suggest placing the new thread in either the Integration/Automation of Office Applications Help (http://www.vbaexpress.com/forum/forumdisplay.php?21-Integration-Automation-of-Office-Applications-Help) or in the Project Assistance (http://www.vbaexpress.com/forum/forumdisplay.php?99-Project-Assistance) Forum folders


Are you limited to using Word? IMHO, Excel based VBA UserForms are easier to design and to automate. Access UserForms might be better suited to your business environment.

Don't ignore the possibility of using a two-step process... Data Entry in Excel/Access based UFs that push the results to a Word based Report.

Gather your Constraints and Resources. Consider Data Points. DPs are merely all the items on all existing forms and reports that must be filled in or are Variants, IOW, places where information can be changed. A type of Resource related to DPs are lists of all the various values that can placed in a DP. For Example...

Consider that "Process Type" is a Data Point, then a List of all Process Types appropriate for that particular Form Field is a Resource. There may be similar, but distinct Resources/Lists. Ie, Lists of Chemicals for two different processes may contain some identical items, and some different items. Combining the two lists allows errors to occur, if a User accidentally selects a wrong Item from the combined list.

A type of Constraint could be Temperature, ie, in a particular Data Entry Field, the value must be between 452 and 474

Obviously, those are merely the Constraints and Resources that apply directly to a Data Entry UserForm. Your Business/Office paradigm will have additional Requirements that must be considered.