Fields Method

The fields method is used to get the column value of the current record.

Syntax

Object.Fields(ColumnInfo)

Arguments:

  • Object: Required. Always the name of ADODB RecordSet object

  • ColumnInfo: Required. It can be Column Name or Index. In case of Index, it will start from Zero

Remarks

The following example illustrates the use of the Fields method.

Example 1:


'Create ADODB.Connection Object
Dim ConnObj   ' Create a variable.
Set ConnObj = CreateObject("ADODB.Connection")
ConnObj.Open("ConnectionString") 'Creates DB Connection by Using Connection String

Dim RecSetObj
Dim CmdTxt
CmdTxt = "SELECT * FROM EMPLOYEE_DETAILS WHERE ID = 101"
Set RecSetObj = ConnObj.Execute(CmdTxt) 'Returns RecordSet

If Not RecSetObj.Eof Then
RecSetObj.Fields(0) 'Returns value of 0th Index Column from the current Record Set
RecSetObj.Fields("SALARY") 'Returns value of SALARY Column from the current Record Set
End If

RecSetObj.Close()
ConnObj.Close() 
Set RecSetObj = Nothing
Set ConnObj = Nothing