Results 1 to 3 of 3

Thread: General reference clarifications

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    Salt Lake City, UT
    Posts
    9

    General reference clarifications

    I have some basic questions about how I reference different parts of a recordset. Lets say that in my query, qryRecordSource, I have records 1,2,3 and 4 which each contain vaules for fields A,B,C,D. Graphically, it looks like this:


    Record..... A.............B.............C.............D
    1.......<valueA1>..<valueB1>..<valueC1>..<valueD1>
    2.......<valueA2>..<valueB2>..<valueC2>..<valueD2>
    3.......<valueA3>..<valueB3>..<valueC3>..<valueD3>
    4.......<valueA4>..<valueB4>..<valueC4>..<valueD4>


    I would then use the code:

    Dim rst as DAO.Recordset
    Dim dbs as DAO.Database
    Dim qd as DAO.QueryDef
    Dim fld as Field
    Dim frm as Form
    Dim ctl as Control

    Set dbs = CurrentDb
    Set qd = dbs.QueryDefs!qryRecordSource
    qd.Parameters![MyParam]= "MyValue"
    Set rst = qd.OpenRecordset


    This much I think I understand. What is the syntax that I need to use to reference the following items:
    • the name of field C?
    • the 2nd record?
    • the value contained in field B of record 4?


    Additionally,
    • what does frm.Name reference?
    • what does fld.Name reference?
    • what does ctl.Name reference?


    Any help understanding this would be greatly appreciated.

    Scott

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    1.
    the name of field C?
    Fields(C).Name
    the 2nd record?
    "Select * From Table1 where A=value2"
    the value contained in field B of record 4?
    This is a bit complicated: you may get all records and then loop through your recordet (and resetting counter at the same time). Wnen counter = 4 then myvalue = Fields(B).Value

    Additionally,


    what does frm.Name reference?
    what does fld.Name reference?
    what does ctl.Name reference?

    Name is a property which represents OBJECT's name. In this case it's a Form, Field and Control respectfully.

    Roy

  3. #3
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Item 1 :

    VB Code:
    1. Sub FieldExample()
    2.    Dim rs As ADODB.Recordset
    3.    Dim fld As ADODB.Field
    4.  
    5.    Set rs = New ADODB.Recordset
    6.    ' Open the recordset, specifying an SQL statement
    7.    ' and a connection string.
    8.    rs.Open "Select * from authors", "DSN=pubs;UID=sa"
    9.    
    10.    Debug.Print "Fields in Authors Table:" & vbCr
    11.  
    12.    ' Loop through each Field object in the
    13.    ' Fields collection of the table and display properties.
    14.    For Each fld In rs.Fields
    15.       Debug.Print "Name:  " & fld.Name & vbCr & _
    16.             "Type:  " & fld.Type & vbCr & _
    17.             "Value: " & fld.Value
    18.    Next fld
    19.  
    20.    ' Close the recordset.
    21.    rs.Close
    22.  
    23. End Sub

    Item 2 :

    VB Code:
    1. IF rst.Eof=False then
    2.  
    3. Rst.MoveNext
    4.  
    5. End If

    Item 3 :

    VB Code:
    1. ' By looping you can get all values :
    2.  
    3. Dim IntNext as Integer, IntMax as Integer, MyData as String
    4.  
    5. IntMax=rst.Recordcount
    6.  
    7. If IntMax>0 Then
    8.  
    9. For IntNext = 1 to IntMax
    10.  
    11. MyData = _
    12. rst.FIELDNAMEHERE1 & vbtab & _
    13. rst.FIELDNAMEHERE2 & vbtab & _
    14. rst.FIELDNAMEHERE3 & vbtab & _
    15. rst.FIELDNAMEHERE4
    16.  
    17. Debug.Print MYDATA
    18.  
    19. rst.MoveNext
    20.  
    21. Next
    22.  
    23. ' This should print the contents of your recordset to the Immedaite Window
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

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