How to insert records in a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shalskedar
    New Member
    • Sep 2009
    • 66

    How to insert records in a table

    With reference to the attachment my Query is I want to insert 1 common value for the Columns Ref No & Address.

    i.e If there are total 6 records in my table,The column Ref No should hold value 310/SA & the column Address should hold value Bedok .


    Here the problem is these 2 columns values lies same for all other worksheets,wher eas other columns always 've a differing value.So in the given table i m trying to insert data in these 2 columns differently.
    Below is my code to insert the values for columns Ref No & Address.
    Code:
    rs.MoveFirst
    For i = 0 To rs.RecordCount
    rs.Edit
    rs.Fields(7) = CStr(Range("D39").Value)
    rs.Fields(9) = CStr(Range("A33").Value)
    rs.Update
    rs.MoveNext
    i = i + 1
    Attached Files
    Last edited by NeoPa; Feb 9 '10, 01:11 AM. Reason: Please use the [CODE] tags provided
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    As you need all values set, you can use a faster UPDATE query instead like:
    Code:
    UPDATE tblYourTableName SET [Ref No] = "310/SA", [Address]="Bedok"
    Nic;o)

    Comment

    • shalskedar
      New Member
      • Sep 2009
      • 66

      #3
      As suggested I m using the below code for updating the table.
      Can u Plz help me out with the syntax.Below is my code but getting error..

      Dim db As DAO.Database
      Dim rs As DAO.Recordset
      Dim str As String
      Set db = DAO.DBEngine.Op enDatabase("C:\---")
      Set rs = db.OpenRecordse t("outer2", dbOpenDynaset)

      db.Execute ("update [outer2] set [outer2].[Refno]=CStr(Range("D3 9").Value)")
      MsgBox "done"
      End Sub
      Getting the error as expected list separator.

      Comment

      • nico5038
        Recognized Expert Specialist
        • Nov 2006
        • 3080

        #4
        Just use:
        Code:
        currentdb.execute ("update [outer2] set [outer2].[Refno]='" & CStr(Range("D39").Value) & "'")
        Nic;o)

        Comment

        • shalskedar
          New Member
          • Sep 2009
          • 66

          #5
          Thanks alot !!Its working

          Comment

          Working...