Reference Form Fields Value - Application-defined Error 2465

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jbrumbau
    New Member
    • Sep 2007
    • 52

    #1

    Reference Form Fields Value - Application-defined Error 2465

    Hello,

    I am trying to refer to fields on a given form from the form query's recordset, essentially from the following commands:
    Code:
        Dim frm As Form 'Refers to the current form
        Dim tagName As String 'Refers to the field in the form's recordset (not a control on the form)
    
        ...
        frm.Fields(tagName).Value 'This gives Error 2465
    My question is how do I refer to a field in the form's record set (not an individual control on the form)? If I use frm![LineTag].Value, it works fine, but frm.Fields(tagN ame).Value does not. Conversely, rs.Fields(tagNa me) does work fine. (note: tagName="LineTa g")

    Please let me know how I can refer to a form's recordset field.

    Thanks!

    ...
    For more info and as to why I need it, here is a large chunk of the function I use to call the segments mentioned above:
    Code:
    Function duplicateRecord(ByRef frm As Form, tableName As String, uniqueCtl As TextBox, tagName As String, ByRef avarExceptionList() As String) As Long     Dim rsExist As Recordset
        Dim keyName As String, keyValue As Long
        Dim tempRecord As Long
        Dim fld As Field
        
    On Error GoTo Err_duplicateRecord
        Set rsExist = CurrentDb.OpenRecordset(tableName)
        keyName = uniqueCtl.ControlSource
        If uniqueCtl.Value > 1 Then
            keyValue = uniqueCtl.Value
            If frm.NewRecord Then
                Call MsgBox("New records cannot be duplicated, please save this record first then try again.", vbExclamation, "Nonexistant Record")
                duplicateRecord = -1
                Exit Function
            ElseIf frm.Dirty Then  
                If MsgBox("Save changes?", vbYesNo, "Unsaved Changes Detected") = vbYes Then
                    MsgBox frm.Fields("LineTag")  
                    If isSaveable(tableName, tagName, frm.Fields(tagName).Value, keyName, keyValue) Then 'This gives Error 2465  
                        Call saveRecord(frm, keyValue)  
                    Else
                        Exit Function
                    End If
                Else
                    Exit Function
                End If
            End If
    	...
    End Function
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    I'm actually a little confused about your question, but to Output a List of Fields comprising a Form's Recordset:
    Code:
    Dim rst As DAO.Recordset
    Dim fld As DAO.Field
    
    Set rst = Me.RecordsetClone
    
    For Each fld In rst.Fields
      Debug.Print fld.Name
    Next
    Sample Output:
    Code:
    EmployeeID
    LastName
    FirstName
    MI
    Title
    TitleOfCourtesy
    BirthDate
    HireDate
    Address
    City
    Region
    PostalCode
    Country
    HomePhone
    Extension
    Photo
    Notes
    ReportsTo
    To actually refer to Fields within the context of a Form's Recordset, once it has been defined:
    Code:
    rst!EmployeeID
    rst!LastName
    rst!FirstName
    rst!MI
    rst!Title
    rst!TitleOfCourtesy
    rst!BirthDate
    rst!HireDate
    rst!Address
    rst!City
    rst!Region
    rst!PostalCode
    rst!Country
    rst!HomePhone
    rst!Extension
    rst!Photo
    rst!Notes
    rst!ReportsTo

    Comment

    • jbrumbau
      New Member
      • Sep 2007
      • 52

      #3
      Just figured it out, I used:
      frm.RecordSet.Fields(tagName )

      Thanks for help ADezii, Me.RecordsetClo ne was a good hint.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        It is usually a good idea to always avoid accessing the actual Form's Recordset in any manner, which is why I always use RecordsetClone whenever appropriate.

        Comment

        Working...