Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assinging array to recordset/table

Status
Not open for further replies.

alh1002

Technical User
Mar 27, 2006
41
US
I have a table, which I put in a recordset, and then to arrays
because I more elaborate functions maniplate the the data.
Now I have this array and I want to put it back into a table

How? I want to cycle thru the array and assign to the table.

 
Do you mean something like:
Code:
Dim rs As DAO.Recordset
Set rs = CurrentDB.OpenRecordset("tblTable")
'Add record to table
rs.AddNew
rs!Field1 = astrArray(0,0)
rs!Field2 = astrArray(0,1)
rs.Update
rs.Close
Set rs = Nothing
 
This is running but I don't see it updating the table, any reason?

code
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("tblNew")

Dim i As Integer
i = 1

With rs
'.MoveFirst
.AddNew

Do While Not .EOF
rs!tdRTp = sngArray(i)
rs!ladder_date = ladderArray(i)
rs!NAV = navArray(i)
rs.Update
rs.MoveNext

i = i + 1

Loop
End With
rs.Close
 
There may be a little confusion. AddNew adds a new record, but is seems that you wish to loop through the recordset and update certain fields. Also, arrays usually begin with 0, not 1.

You could try:
Code:
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("tblNew") 

Dim i As Integer
i = 1 'Or 0

With rs
  .MoveFirst
  '.AddNew
  
  Do While Not .EOF
    .Edit
    !tdRTp = sngArray(i)
    !ladder_date = ladderArray(i)
    !NAV = navArray(i)
    .Update

    .MoveNext

    i = i + 1
      
  Loop
End With
rs.Close
Set rs = Nothing
 
the issue I am having. I run this (running the module); and then I look at the table and nothing is there. Is somehow the recordset not being associated with the table. Currently the table is empty, as I am testing this.
 
If your table is currently empty then the recordset is also empty and .EOF will return TRUE ... so you will never get into the Do While NOT .EOF loop. Maybe you need something like
Code:
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("tblNew") 

Dim i As Integer
With rs
   For i = LBound(sngArray) To UBound(sngArray)
     .AddNew
     !tdRTp = sngArray(i)
     !ladder_date = ladderArray(i)
     !NAV = navArray(i)
     .Update
   Next
End With
rs.Close
Set rs = Nothing

[small]On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. (Charles Babbage)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top