Results 1 to 3 of 3

Thread: Need help with using datafields

  1. #1

    Thread Starter
    Addicted Member P.S.W.'s Avatar
    Join Date
    Aug 2000
    Posts
    146

    Question

    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



  2. #2
    Guest
    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

  3. #3

    Thread Starter
    Addicted Member P.S.W.'s Avatar
    Join Date
    Aug 2000
    Posts
    146

    Smile 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
  •  



Click Here to Expand Forum to Full Width