Assigning values to table fields in VB

filo77

Registered User.
Local time
Yesterday, 20:20
Joined
Jul 13, 2004
Messages
16
I have a couple of questons for you:

How do I assign a value that comes from a form and is inputed by the user to a double variable. Let's say I have a field in a form called number and I have declared a variable dim sample as double. I need to assign the value of the field to the variable in order to do some calculations that user need not to see.

I tried set sample = Me.Number, but it didn't work and displayed some sort of property type error.

My next question is, once I am done with the calculations I need to save the result in a table field. Again the user need not to see whats going on.

A complete example would be a form with two fields one called number1 and another one called number2 and a close button.

When the user provides values to both number1 and number2 and clicks the close button, before the form is closed I need to assign those two values to two variables, calculate, say their sum, which is assigned to another variable called results, and then the value of results is assign to a field in a table, say Table1, field1.

Once again this needs to be hidden from the user, so I am assuming that I have to do this as a VB Module.

Any suggestions???????

Thanks for your help.

filo
 
filo,

You are making this too complicated.

Just make a table:

tblTest:
Number1 Number
Number2 Number

Then just have the wizard base a form on it. You now have a
database and a means to view/maintain your data.

Your form has txtNumber1 and txtNumber2 on it. Add a third
field and call it txtFieldCalc.

Make a query that is based on your table. Add your two table
numbers to it, and add a new field to the query:

MyCalc: [Number1] + [Number2]

Now get your form back in design view. Set the RecordSource
for your form to the new query. Set the ControlSource for
txtFieldCalc to MyCalc.

Run your form.

Now you can modify your query, not change your form and
get the results.

MyCalc: [Number1] * [Number2]

Experiment with it.

Wayne
 
Thanks

Thanks.

I guess I can always hide the field from the user, ah?


Thank you very much.

filo
 

Users who are viewing this thread

Back
Top Bottom