PDA

Click to See Complete Forum and Search --> : Need help with using datafields


P.S.W.
Aug 25th, 2000, 06:43 PM
I have a situation using this kind of code in a routine:

iValue = dbRecordset![Field1]

(bang notation using ADO recordset)

Thing is, I want to assign the data field to a variable, and then use the variable in the code, something like this:

Dim sDataField as String
sDataField = "[Field1]"

iValue = dbRecordset! & sDataField

--Of course, this doesn't work! I don't know the proper way to set this up. I would be grateful for any suggestions on how to do this.

Thanks,
PSW

Aug 28th, 2000, 03:59 AM
if you want to store the FieldName in a string-variable, then use the following syntax to reference fields in your recordset:

'*********************************************************
Dim rs As Recordset ,strName As String

strName = "Name"
Debug.Print rs.Fields(strName)

'*********************************************************

another option would be storing the reference to a field in an object variable:

'*********************************************************

Dim rs as Recordset, fldName as Field, fldGender as Field

With rs
' open your recordset here
set fldName = .Fields("Name")
set fldGender = .Fields("Gender")
If Not (.RecordCount = 0) Then
.MoveFirst
Do Until .Eof
Debug.Print "Name=" & fldName & ", Gender=" & fldGender
.MoveNext
Loop
End If
.Close
End With

'*********************************************************

best regards

Alexander

P.S.W.
Aug 28th, 2000, 01:49 PM
Alexander,

The syntax you suggested works great. Thanks for the help!

PSW