Forms to Table Calculation

H

hcso

We have a form that has unbound calculation fields that we want to link to a
table. Both the form and the table have already been created. How should I
start my Visual Basics entry? I keep trying the following and both keep
giving me a syntax error when I try to open the table, or they give me an
#error or ?Name in the field on the Form.

Dim Rs As Recordset
Set Rs = CurrentDb.OpenRecordset("Issues")
Rs.AddNew
Rs![Total_Hrs] = Me![Total_Hours]

Rs.Update
Rs.Close
Set Rs = Nothing

Any Suggestions? We have altered it several ways to no avail.
 
G

Graham Mandeno

Hi hsco

If you have no code at all, then does your Total_Hours textbox show the
correct result? If not, address that problem first.

Where is this code? Is it in the Click event of a button on your form?

Are you really wanting to add a new record to your Issues table with the
Total_Hrs field filled in but nothing else?

Is your whole form unbound, or just the textbox?
 
J

John W. Vinson/MVP

We have a form that has unbound calculation fields that we want to link to a
table. Both the form and the table have already been created. How should I
start my Visual Basics entry? I keep trying the following and both keep
giving me a syntax error when I try to open the table, or they give me an
#error or ?Name in the field on the Form.

Dim Rs As Recordset
Set Rs = CurrentDb.OpenRecordset("Issues")
Rs.AddNew
Rs![Total_Hrs] = Me![Total_Hours]

Rs.Update
Rs.Close
Set Rs = Nothing

Any Suggestions? We have altered it several ways to no avail.

I'd "unask" the question.

It's very, very rarely necessary or appropriate to store a calculated
field such as total_hours. If it can be derived from data existing in
your tables, just recalculate it when it's needed; storing it risks
data validity errors, since either the stored total_hours field or one
of the underlying fields which go into the calculation could be
changed, and then you would have a total WHICH IS WRONG, with no easy
way to detect that fact.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top