ms access - Using an expression in a numeric form control -
i have access form textbox bound currency field in table. expected, other numerical entry generates error. occasionally, users need enter several amounts , have added , result entered currency field.
to accomplish this, users enter equal sign followed valid arithmetical string evaluate number in excel cell. example, if user enters "=5.31+2" want field evaluate "7.31" , use value passed table when record updated or saved. current workaround use calculator application isn't ideal solution.
i tried following code , applied both beforeupdate , onlostfocus events of textbox (named "tbxtotal_paid") neither worked. got "the value entered not valid field" error.
dim charct integer dim evalstr string if left(tbxtotal_paid, 1) = "=" charct = len(tbxtotal_paid) evalstr = right(tbxtotal_paid, charct - 1) me.tbxtotal_paid = ccur(evalstr) end if is applying code incorrect event or coding issue? assistance appreciated.
for me code looks fine might put in wrong place.
like said acess giving error because textbox bound currency-field. never accept non-numerical values because value-checking code fires before before_update-event.
i think best solution hide bound text box using me.tbxtotal_paid.visible = false , creating surrogate textbox not bound. put code in beforeupdate-event or change-event of surrogate. @ end should check final result isnumeric(). way surrogate textbox writes correct values bound hidden textbox , numbers arrive @ table.
an alternative change currency column string-field not wise because of potential wrong data in database.
Comments
Post a Comment