GeertG
GeertG

Reputation: 158

MS Access VBA changing TextBox filled by a ComboBox

i got a question about some "simple" MS Access vba. I got a ComboBox. When an item is selected, various TextBoxes are updated. Now i want to edit the text that is put in a TextBox after an item is selected (Because the data is filled with a very much spaces, so i want them out).

I tryed "before update", "after update", "on dirty" and "on change" events, but none of them seems to be the right one.. Anyone knows what i'm looking for? Thanks

Upvotes: 0

Views: 1316

Answers (1)

Chris Rolliston
Chris Rolliston

Reputation: 4808

Two possible ways:

(1) Instead of just entering the field name for each text box's ControlSource property, enter an expression, e.g. =Replace([SomeField], " ", ""). This assumes the text boxes are supposed to be read-only.

(2) Don't use data binding at all, and instead set each text box's Value property explicitly:

Dim RS As DAO.Recordset
Set RS = CurrentDB.OpenRecordset(SQL)
txtWhatever.Value = Replace(RS!SomeField, " ", "")
txtAnother.Value = Replace(RS!AnotherField, " ", "")

In the second case updating the data source with any altered values will need to be handled explicitly too.

That said, if the data has unnecessary spaces, surely they should be cleaned up at source, rather than as the data is put into the UI...?

Upvotes: 1

Related Questions