I have got an application that I would like customers to have the ability to enter simple maths into, using the calculated value saved within the table.
- User makes its way into "1+5" right into a text box.
- The solution 6 is saved within the database table.
Presently, entering "1+5" during my number form area leads to a mistake re: 'entering text right into a number field'. Can there be any method of doing this?
You are able to write a VBA script to parse the input and perform any needed information. This may be triggered by an unbound form field's BeforeUpdate event.
- Produce a area named Field1 for that calculated value (certain to the right database area).
- Add an unbound area for your form and title it Input1.
- In Design view, right-click Input1 and select Qualities. Under Occasions -> Before Update, click on the "..." button.
- Place the VBA code which i wrote (below).
- Save your valuable changes and close the VBA editor.
- Go back to Form view and enter a manifestation to your Input1 area. Whenever you tab from the area, the expression is going to be examined and also the value can look in Field1.
Observe that, for reasons of security and/or data integrity, you may want to sanitize your user input before evaluating it as being a manifestation. The particulars of "how" and "why" fall outdoors the scope from the original question.
Private Sub Input1_BeforeUpdate(Cancel As Integer) ' TO-DO: Validate/sanitize input as necessary for security & validity; ' Exit Sub prior to the Eval() if we see something we don't like Dim result As Variant result = Eval(Input1.Value) ' Evaluate the contents of Input1 If IsNumeric(result) Then Field1 = result ' Save any numeric result to Field1 End Sub