how to insert data in access table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prasad joshi
    New Member
    • Aug 2012
    • 30

    how to insert data in access table

    i am making a program

    in that i am doing calculations

    after doing calculation i want to store calculated value in another table

    but i dont know how to insert calculated data in table

    program gives error in this part of code

    Code:
    ......................................
    rs.Edit
    rs.Fields("vol") = ("strComp")
    rs.Update
    ............................

    following is my code
    Code:
     Private Sub Command0_Click()
    Dim dbsCurrent As Database
    Dim rsCount As Recordset
    Dim result As String
    Dim result2 As String
    Dim val As Double
     
    Set dbsCurrent = CurrentDb
    Set rsCount = _
       dbsCurrent.OpenRecordset _
          ("SELECT Field1 FROM Query1 WHERE (id)= 3")
    result = rsCount![Field1]
    MsgBox (result)
     
    Set rsCount = _
       dbsCurrent.OpenRecordset _
          ("SELECT Field3 FROM Query1 WHERE (Field1)= 'Protokollersteller'")
    result2 = rsCount![Field3]
    MsgBox (result2)
     
    Set rsCount = _
       dbsCurrent.OpenRecordset _
          ("SELECT Field3 FROM Query1 WHERE (Field1)= 'Bezugsfrequenz'")
    val = rsCount![Field3]
    MsgBox (val)
     
    Set rsCount = _
       dbsCurrent.OpenRecordset _
          ("SELECT Field3 FROM jarman WHERE (Field1)= 'Bezugsfrequenz'")
    val = rsCount![Field3]
     
    val = val + 50
    
    MsgBox (val)
     
    rsCount.Close
     
    Dim rs As Recordset, db As Database, strComp As String
     
    Set db = CurrentDb
     
    Set rs = db.OpenRecordset("data", dbOpenDynaset)
     
    strComp = val
     
    'You would now need to find the record that
    'you wanted to add a comp value to.
    'You could use the FindFirst method of the recordset to do this.
     
    rs.Edit
    rs.Fields("vol") = ("strComp")
    rs.Update
     
    DoCmd.OpenForm "type"
     
    End Sub
    please help me.....
    Last edited by zmbd; Sep 4 '12, 05:22 AM. Reason: (z) Added code tag to first section. Removed extra returns and stepped code in second section of code.
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    PJ:

    "...the program give error..."
    What is the error number and what is the error description.

    The exact line of the code that the error occurs would be most helpful... the debugger will help you there.

    However, after reviewing your code:
    I don't see where in lines 38 thru 53 of the second code block that you have actually opened the record set, and moved to the actual record either thru adding a new record or by selecting a record for editing. Lines 46 thru 48 - the comment - would appear to point you in the correct direction. However, the error could also be in "val" who knows... you need to post the actual error.
    (also try this: RS![Vol] = strComp assuming the datatypes are correct.

    In lines 9 thru 30 of the second code block:
    You open and re-open record sets using the same name without closing the record set... this is not best practice and may very well lead to the corruption of your database.

    Normally one does not store the calculated value in the dataset unless it is for a snap shot in time... i.e. tax or discount on an item where these may change and the value is needed for historical reasons. Calculations are usually handled in the query or the report at runtime.

    -z
    Last edited by zmbd; Sep 4 '12, 05:52 AM. Reason: added thought

    Comment

    • prasad joshi
      New Member
      • Aug 2012
      • 30

      #3
      Calculations are usually handled in the query or the report at runtime.

      means what

      can we do complex operations on report at run time?????

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        PJ,

        Two new questions that deserve their own threads... and simply, asked and answered; however, in a new thread we can go more indepth.

        Let us work thru the issue you've asked about in this thread.

        -Z

        Comment

        Working...