Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 32
  1. #16
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479

    The datasheet forms me.recordsetclone index number for the selected field is wanted
    Does that describe it better?

  2. #17
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    not in the slightest.

    Do you mean the field index for a specific field? if so then perhaps something like

    Code:
    dim index as integer
    
    index=0
    while mycontrol.controlsource<>me.recordsetclone.fields(index).name
      index=index+1
    wend

  3. #18
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479
    Brilliant @CJ, that's it Thank you.
    If I'd known to call it a field index would that have helped? My description still sounds ok to me!

  4. #19
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I agree with CJ's "not in the slightest."

    Your response in post #16 reminds me of " the rope is 37...???"
    Glad you have a solution, and happy that CJ is still the best guesser we have!

  5. #20
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    If I'd known to call it a field index would that have helped? My description still sounds ok to me!
    calling things by their proper names makes a big difference. It's not that difficult, just google the terms of reference - such as 'recordsets'. Only you know your terms of reference. And explaining in simple terms what you are trying to do also helps - at least then we kind of know what area you are working in

  6. #21
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479
    What language do you guys speak? !!
    > The datasheet forms me.recordsetclone index number for the selected field is wanted
    The Form uses Datasheet View
    Me.RecordSetclone. index number is another way of saying "field index", surely ?
    Is wanted needs no explanation.
    Anyway solution was great and everyones feedback is appreciated. I had a fix but it was pretty clunky. I'd made a table with the field name and the Control name
    and looped using DLookUp to compare them. CJs method is way better. And very helpful to see other ways of doing things.

  7. #22
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    I'm baffled as to why you didn't weren't at least close in post 5. You asked
    So if control is called Test - get x for r(x).Name= "Test"
    I gave you
    If rs.Fields(i).Name = "Test" Then MsgBox i + 1
    If the field name is Test, the msgbox was giving you the 1-based field position in the form recordset. I'd call that the logical/intuitive position.
    If you wanted the index, all you had to do was remove the +1?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #23
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    Me.RecordSetclone. index number is another way of saying "field index", surely ?
    No, it is not. You were told that a recordset does not have an index number. Only the fields have index numbers wrt recordsets of any kind.
    Consider the recordset as your house, the house has several doors (recordset fields). The garage door index is 3 (the 4th door according to zero based count).
    Would you ask what is the index number of your house when given the name "front" for the door?
    Last edited by Micron; 11-09-2022 at 04:53 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #24
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479
    Apologies if I missed a point you'd made ab out the +1
    To me an index is a number that references something (as x in r(x))
    If I needed a number for 'front' I'd have to find its index.

  10. #25
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    If I needed a number for 'front' I'd have to find its index.
    Yes if you meant find the index by looking at the field names in a counting loop. But, you cannot return the index for any field in a recordset by passing its name to anything. You have to know the index number to get the name. Both CJ's and my code makes use of a counter loop that tests the name of a field and says, OK since we're at 5 in the counter now, the index must be 5 based on the name we're looking for. Neither code passes the name to anything and returns the index. The magic is all in the counting loop. BTW, if the index value is 5, it is the 6th field in the fields collection of the recordset.
    Last edited by Micron; 11-09-2022 at 05:46 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #26
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479
    Thanks @Micron. Understood. Here's what I did, but now replaced. And no need for the table.
    Code:
    Function RSNumberFor(controlName) As Integer
        Dim i As Integer
        Dim rs As DAO.Recordset
        RSNumberFor = -1
        Set rs = Me.subCDTracks.Form.RecordsetClone
        If Not (rs.EOF And rs.BOF) Then
             For i = 0 To rs.Fields.Count - 1
                If Nz(DLookup("[Table]", "tblControlNames", "[Form] = " & Chr$(34) & controlName & Chr$(34))) = rs.Fields(i).Name Then
                   RSNumberFor = i
                   Exit For
                End If
             Next
        End If
        Set rs = Nothing
    End Function

  12. #27
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    I'll still ask my question again, as I must be being thick, I still can't see what the point of this exercise is.

    You know the field name, by definition you should know it's data type, so what do you need the recordset field index actually for?
    What's the purpose?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  13. #28
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Been wondering the same thing as Minty
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  14. #29
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479
    I didn't answer answer @Minty as I wasn't sure what to say. It seemed obvious, wanting to know about your data and its structure etc.
    In this particular case I was building a Msgbox of all 'parts' of my field, instantly showing their names and addressing to help me with coding.

  15. #30
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    It seemed obvious, wanting to know about your data and its structure etc.
    Maybe creating table relationships would take care of that. When you need a reminder, you look at them. Unless I've misunderstood that statement, I don't see how knowing the index of a field within a recordset helps at all with the data and the structure of the data.
    Recordset/field "structure" is somewhat fluid, given that the representation of what lies beneath can be massaged through queries and recordsets, so those are not really structure at all. At least that's my take.
    Last edited by Micron; 11-10-2022 at 05:49 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. OLE or Active X Control Error
    By WCStarks in forum Forms
    Replies: 6
    Last Post: 01-29-2018, 05:27 PM
  2. Replies: 4
    Last Post: 02-18-2016, 12:06 PM
  3. Detect which control is active
    By Williams485 in forum Forms
    Replies: 4
    Last Post: 07-23-2015, 10:00 AM
  4. Active Control on Image
    By LonghronJ in forum Modules
    Replies: 12
    Last Post: 07-15-2015, 03:57 PM
  5. Active X form control
    By amitsingha4u in forum Access
    Replies: 2
    Last Post: 05-18-2010, 12:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums