Skip to content

Picking up data from textboxes

Q:  Mark Jackson writes that he is having trouble getting code that picks up values from textboxes on a form to work – a Help topic said that the focus must be on the control in order to pick up the topic.

A:  Some of those Help topics are very old.  You don’t need to have focus on a textbox to read the value.  However, sometimes the value won’t be read correctly unless you save the form (say if the value was just entered), so it is a good idea to do a DoCmd.RunCommand acCmdSaveRecord command before reading a value from a control on a form.  (This is the modern syntax; some Help topics and Wizards still use the ancient DoMenu commands from Access 95 or earlier.)  Use the Value property to get the data entered into controls on Access forms.  When working with form controls, usually it is a good idea to run code off the AfterUpdate event of the control, and always give your controls meaningful names (it is very hard to know what Text69 is, in code).

Another possible source of errors is that the control that has the same name as its bound field (if you make a form from the New Form dialog, this is what you will get).

About this author