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
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