Share via

Undefined function <NAME> in expression

Anonymous
2016-07-20T15:26:17+00:00

I'm trying to create a procedure on the double click event of a text box to open a form in datasheet view of all records with a matching field value. For this I've tried creating two variables to store the field and value for the filter criteria, but when I tried substituting these into my filter string I got an error #3085.

This is the code I have in my OnLoad event of the datasheet I want returned:

Private Sub Form_Load()

    If IsNull(strValue) Then

        Me.FilterOn = False

    Else

        Me.Filter = "" & strField & " = '" & strValue & "'"

        Me.FilterOn = True

    End If

End Sub

The error #3085 description I get is:

"Undefined function 'tblSelfContained.Fields' in expression."

I tried using 'tblSelfContained.Fields(strField)' in my filter string but since removed it and yet am still getting the error.

Anybody got any idea as to why?

Much appreciated,

Seb

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2016-07-22T11:13:59+00:00

Instead of

strField & " = 'strValue'"

use

strField & " = '" & strValue & "'"

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

17 additional answers

Sort by: Most helpful
  1. Anonymous
    2016-07-20T15:44:55+00:00

    Also; just realised that access claims the error is happening on the dbl click event of the textbox.. I commented out the whole on load procedure and I'm still getting the exact same error..

    Here's the code for the dbl click event:

    Private Sub txtWeight_DblClick(Cancel As Integer)

        strField = "Weight"

        strValue = Me.txtWeight

        DoCmd.OpenForm "frmSelfContainedSorted"

    End Sub

    Apparently the error occurs on the line "DoCmd.OpenForm "frmSelfContainedSorted"

    And I've checked my references, none are missing..

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-07-20T15:41:41+00:00

    Hi, try with

    Me.Filter =  """" & strField & " = '" & strValue & "'"""

    Ciao Mimmo

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-07-20T15:33:14+00:00

    The value is "Weight"

    Was this answer helpful?

    0 comments No comments
  4. HansV 462.6K Reputation points
    2016-07-20T15:29:57+00:00

    What is the value of strField when the error occurs?

    Was this answer helpful?

    0 comments No comments