Forms to Table Calculation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hcso
    New Member
    • Jul 2008
    • 1

    Forms to Table Calculation

    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.
    Code:
    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.
    Last edited by NeoPa; Aug 5 '08, 12:06 AM. Reason: Please use the [CODE] tags provided
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    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!

    Comment

    • PianoMan64
      Recognized Expert Contributor
      • Jan 2008
      • 374

      #3
      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.
      Code:
      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.
      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.

      Comment

      Working...