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!

Beginner help: Update a table from a recordset

Status
Not open for further replies.

towser

Programmer
Feb 19, 2001
29
GB
Basically I'm running this bit of code in order to update records in a table, however the code will only update the 1st record and not the full record set. I'm brand new to VBA and I'm very frustrated.

I was thinking maybe a function or a loop to apply code to each record in turn


Please please help or point in the right direction, thanks.

Dim WorkDB
Set WorkDB = CurrentDb

Dim WorkRS
Set WorkRS = WorkDB.OpenRecordset("TCI Data 2")

With WorkRS.edit

Dim Trimcode
Trimcode = RTrim(WorkRS![Postcode Full])
WorkRS![Exposure] = 1

If Len(Trimcode) = 8 Then WorkRS![Postcode Sector] = Mid(Trimcode, 1, 6)
If Len(Trimcode) = 8 Then WorkRS![Level] = "Sect"

If Len(Trimcode) = 7 Then WorkRS![Postcode Sector] = Mid(Trimcode, 1, 5)
If Len(Trimcode) = 7 Then WorkRS![Level] = "Sect"

If Len(Trimcode) = 6 Then WorkRS![Postcode Sector] = Mid(Trimcode, 1, 4)
If Len(Trimcode) = 6 Then WorkRS![Level] = "Sect"

If Len(Trimcode) < 6 Then WorkRS![Postcode Sector] = (Trimcode)
If Len(Trimcode) < 6 Then WorkRS![Level] = "Out"

WorkRS.Update
WorkRS.Close
End With



 




Hi,

1. the recordset is the entire table. Is that your intention?

2. you must loop thru the recordset, using the MoveNext method, until the EOF property is true.
Code:
with WorkRS
  do while (not .eof)
    

    .update
    .movenext
  loop
  .close
end with


Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top