P
Patrick Maslanka
Im new to VBA programming, and looking for some help on how to open a table
as a RecordSet, so that i can parse through it and perform tests and
modifications on the data in the table.
What i need to do, is move thru the table from begining to end, in the order
that it is sorted, and check a field in the record. If the field is blank (
NULL ) then i need to set the field equal to the value of the previous
records field, if a test condition is true.
I have written the following function code, and would appreciate someone
looking at it, and tell me if im doing it right, or tell me what im doing
wrong.
I believe i have coded it correctly ( as far as the logic), but the syntax
may be wrong. Specifically, im not sure how to set which table im using ( the
set db and set rst lines )
Thanks in advance for your assistance.
-------------------------------------------
Public Function PopulateEmptySpec()
Dim PreviousSpec As String
Dim db As Database
Dim rst As Recordset
Set db = DBEngine.Workspaces(0).Databases(0) ' ??? Need Help Here ???
Set rst = db.OpenRecordset("OID") ' ??? Open Table "OID" ???
rst.MoveFirst ' Goto 1st Record
PreviousSpec = rst!Spec ' Set String to Record's
"Spec" field
rst.MoveNext
Do Until rst.EOF
If rst!Spec = "" Then ' If current Record's Spec
field is empty
If PreviousSpec = "EFI" Then ' copy previous Record's
Spec field if
Set rst!Spec = "EFI" ' that field contained
"EFI" or "IOT"
If PreviousSpec = "IOT" Then
Set rst!Spec = "IOT"
rst.Update ' Write to the table
before moving
PreviousSpec = rst!Spec ' Save Record's "Spec"
field for compare
rst.MoveNext
Loop
End Function
------------------------------------
as a RecordSet, so that i can parse through it and perform tests and
modifications on the data in the table.
What i need to do, is move thru the table from begining to end, in the order
that it is sorted, and check a field in the record. If the field is blank (
NULL ) then i need to set the field equal to the value of the previous
records field, if a test condition is true.
I have written the following function code, and would appreciate someone
looking at it, and tell me if im doing it right, or tell me what im doing
wrong.
I believe i have coded it correctly ( as far as the logic), but the syntax
may be wrong. Specifically, im not sure how to set which table im using ( the
set db and set rst lines )
Thanks in advance for your assistance.
-------------------------------------------
Public Function PopulateEmptySpec()
Dim PreviousSpec As String
Dim db As Database
Dim rst As Recordset
Set db = DBEngine.Workspaces(0).Databases(0) ' ??? Need Help Here ???
Set rst = db.OpenRecordset("OID") ' ??? Open Table "OID" ???
rst.MoveFirst ' Goto 1st Record
PreviousSpec = rst!Spec ' Set String to Record's
"Spec" field
rst.MoveNext
Do Until rst.EOF
If rst!Spec = "" Then ' If current Record's Spec
field is empty
If PreviousSpec = "EFI" Then ' copy previous Record's
Spec field if
Set rst!Spec = "EFI" ' that field contained
"EFI" or "IOT"
If PreviousSpec = "IOT" Then
Set rst!Spec = "IOT"
rst.Update ' Write to the table
before moving
PreviousSpec = rst!Spec ' Save Record's "Spec"
field for compare
rst.MoveNext
Loop
End Function
------------------------------------