You need to reference the field of the concerned column for each row.
This can be done by creating a field object that references the field of the
recordset. Alternatively, you can interrogate the value from the recordset
fields collection.
Sub MySub()
Dim db As Database
Dim rst As Recordset
Dim MyField As String
Dim MyLength As Integer
Set db = DBEngine.Workspaces(0).Databases(0)
Set rst = db.OpenRecordset("olive")
Do Until rst.EOF
MyField = rst("link").Value 'interrogate field value from field item
of fields collection of recordset
If Len(MyField) > 30 Then
Debug.Print ("too long")
End If
rst.MoveNext
Loop
'remember to teardown the recordset and destroy your objects
rst.close
set rst = nothing
set dbs = nothing 'don't close the db because it is the instance that ms
access is using
End Sub
Sub MySub()
Dim db As Database
Dim rst As Recordset
Dim MyField As DAO.Field
Dim MyLength As Integer
Set db = DBEngine.Workspaces(0).Databases(0)
Set rst = db.OpenRecordset("olive")
Set fld = rst.Fields("link")
Do Until rst.EOF
'Object reference
If Len(MyField.Value) > 30 Then
Debug.Print ("too long")
End If
rst.MoveNext
Loop
'remember to teardown the recordset and destroy your objects
rst.close
set rst = nothing
set dbs = nothing 'don't close the db because it is the instance that ms
access is using
End Sub
Ted McNeal
Quote:
> If anyone could tell me why this isn't working, I'd be
> very grateful.
> I have a table called 'olive' which contains a field
> called 'link'.
> I want to print the ID of each record in the 'link' field
> that is over a certain length. Instead this code prints
> each ID for each record.
> Any help much appreciated.
> Sub MySub()
> Dim db As Database
> Dim rst As Recordset
> Dim MyField As String
> Dim MyLength As Integer
> Set db = DBEngine.Workspaces(0).Databases(0)
> Set rst = db.OpenRecordset("olive")
> MyField = rst("link")
> Do Until rst.EOF
> If Len(MyField) > 30 Then
> Debug.Print ("too long")
> End If
> rst.MoveNext
> Loop
> End Sub