|
-
Aug 25th, 2000, 06:43 PM
#1
Thread Starter
Addicted Member
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
#2
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
-
Aug 28th, 2000, 01:49 PM
#3
Thread Starter
Addicted Member
Thanks!
Alexander,
The syntax you suggested works great. Thanks for the help!
PSW
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|