Connecting Tech Pros Worldwide Forums | Help | Site Map

Forms to Table Calculation

Newbie
 
Join Date: Jul 2008
Posts: 1
#1: Jul 28 '08
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.
Expand|Select|Wrap|Line Numbers
  1. Dim Rs As Recordset
  2. Set Rs = CurrentDb.OpenRecordset("Issues")
  3. Rs.AddNew
  4. Rs![Total_Hrs] = Me![Total_Hours]
  5.  
  6. Rs.Update
  7. Rs.Close
  8. Set Rs = Nothing
Any Suggestions? We have altered it several ways to no avail.

Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,268
#2: Jul 28 '08

re: Forms to Table Calculation


Greetings, Dear Friend!

Just passing through; not too savvy at calculations through forms... Wondered if you could try making your calculations in a query and load to the form. I am not sure what you hope to achieve, so do stay tuned for a better answer from experts here.

You may need to grab data from one table, calculate through form, then add to table a second table, in which case I think your form may still need the assistance of a query, or intense form functions to handle the task, surely possible, I just do not know. Have you previously searched this forum on form calculation?

Hope you get it going:-)

In a bit!
Expert
 
Join Date: Jan 2008
Posts: 365
#3: Jul 28 '08

re: Forms to Table Calculation


Quote:
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.
Expand|Select|Wrap|Line Numbers
  1. Dim Rs As Recordset
  2. Set Rs = CurrentDb.OpenRecordset("Issues")
  3. Rs.AddNew
  4. Rs![Total_Hrs] = Me![Total_Hours]
  5.  
  6. Rs.Update
  7. Rs.Close
  8. Set Rs = Nothing
  9.  
Any Suggestions? We have altered it several ways to no avail.
Hey HCSO:

It is normally considered poor form to store a calculated field in a database just in case you ever need to go back and recalculate that value again. It is normally preferred to calculate that value every time that particular field needs to be displayed in case that some additional values get added to the database.

Now to solve the problem you're having with the code, you're going to have to decide whether your going to manage the database connection for the form, or if you're going to let access doing it. All you're simply doing here is adding a blank record into Table Name "Issue" with the field "Total_Hrs" being posted. If you have any required fields in the table, then you're going to generate an error.

What you're going to need to do is what I suggest and simply calculate the field, that way when you come back to that record, it will display the calculated field on the form.

If you can send me what you're wanting to calculate, then I would be able to give a specific answer as to how to accomplish this.

Hope that helps,

Joe P.
Reply