CodeContextObject / Converted Macro

imodett 41 Reputation points
2021-03-31T17:47:13.377+00:00

I receive the following error:

Run-Time error 2467
The Expression you entered refers to an object that is closed or doesn’t exist.

And the following line is highlighted in my code:

Set objCurrent = CodeContextObject

Can anyone assist with me with finding the solution?

Here is the code. The code has been converted from a macro.

Option Compare Database
Option Explicit

'------------------------------------------------------------
' Search
'
'------------------------------------------------------------
Function Search()

Dim objCurrent As Object
Set objCurrent = CodeContextObject

    On Error GoTo Search_Error
10        With CodeContextObject.Name
20            If (Eval("[Form]![SearchBox] Is Null Or [Form]![SearchBox]=""""")) Then
                  ' Clear Filter when search box empty
30                DoCmd.ApplyFilter "", """""", ""
40                DoCmd.GoToControl "SearchBox"
50                DoCmd.SetProperty "cmdSearchClear", acPropertyVisible, "0"
60                DoCmd.SetProperty "iconSearchClear", acPropertyVisible, "0"
70                DoCmd.SetProperty "cmdSearchGo", acPropertyVisible, "-1"
80                DoCmd.SetProperty "iconSearchGo", acPropertyVisible, "-1"
90            End If
100           If (Eval("[CurrentProject].[IsTrusted] And ([Form]![SearchBox] Is Null Or [Form]![SearchBox]="""")")) Then
110               .SearchBox.Text = ""
120           End If
130           If (Eval("[Form]![SearchBox] Is Null Or [Form]![SearchBox]=""""")) Then
140               End
150           End If
160           If (VarType(.Form!SearchBox) <> 8) Then
170               End
180           End If
190           DoCmd.SetProperty "cmdSearchGo", acPropertyVisible, "-1"
200           DoCmd.SetProperty "iconSearchGo", acPropertyVisible, "-1"
210           If (Eval("([Form]![SearchBox] Is Null Or [Form]![SearchBox]="""") And [cmdSearchClear].[Visible]<>0")) Then
220               DoCmd.SetProperty "cmdSearchClear", acPropertyVisible, "0"
230               DoCmd.SetProperty "iconSearchClear", acPropertyVisible, "0"
240               End
250           End If
              ' Handle "'s in search
260           TempVars.Add "strSearch", Replace(.Form!SearchBox, """", """""")
              ' Build the Filter for the Task list
270           If (.Form.Name = "Task List") Then
280               TempVars.Add "strFilter", "([Title] Like "" * " & [TempVars]![strSearch] & " * "" )"
290           End If
300           If (.Form.Name = "Task List") Then
310               TempVars.Add "strFilter", TempVars!strFilter & " OR ([Description] Like "" * " & [TempVars]![strSearch] & " * "" )"
320           End If
330           If (.Form.Name = "Task List") Then
340               TempVars.Add "strFilter", TempVars!strFilter & " OR ([Status] Like "" * " & [TempVars]![strSearch] & " * "" )"
350           End If
360           If (.Form.Name = "Task List") Then
370               TempVars.Add "strFilter", TempVars!strFilter & " OR ([Priority] Like "" * " & [TempVars]![strSearch] & " * "" )"
380           End If
              ' Build the Filter for the Contact list
390           If (.Form.Name = "Contact List") Then
400               TempVars.Add "strFilter", "([Last Name] Like "" * " & [TempVars]![strSearch] & " * "" )"
410           End If
420           If (.Form.Name = "Contact List") Then
430               TempVars.Add "strFilter", TempVars!strFilter & " OR ([First Name] Like "" * " & [TempVars]![strSearch] & " * "" )"
440           End If
450           If (.Form.Name = "Contact List") Then
460               TempVars.Add "strFilter", TempVars!strFilter & " OR ([E-mail Address] Like "" * " & [TempVars]![strSearch] & " * "" )"
470           End If
480           If (.Form.Name = "Contact List") Then
490               TempVars.Add "strFilter", TempVars!strFilter & " OR ([Company] Like "" * " & [TempVars]![strSearch] & " * "" )"
500           End If
510           If (.Form.Name = "Contact List") Then
520               TempVars.Add "strFilter", TempVars!strFilter & " OR ([Job Title] Like "" * " & [TempVars]![strSearch] & " * "" )"
530           End If
540           If (.Form.Name = "Contact List") Then
550               TempVars.Add "strFilter", TempVars!strFilter & " OR ([Notes] Like "" * " & [TempVars]![strSearch] & " * "" )"
560           End If
570           If (.Form.Name = "Contact List") Then
580               TempVars.Add "strFilter", TempVars!strFilter & " OR ([Zip/Postal Code] Like "" * " & [TempVars]![strSearch] & " * "" )"
590           End If
              ' Apply the Filter
600           DoCmd.ApplyFilter "", TempVars!strFilter, ""
610           TempVars.Remove "strFilter"
620           TempVars.Remove "strSearch"
630           DoCmd.SetProperty "cmdSearchClear", acPropertyVisible, "-1"
640           DoCmd.SetProperty "iconSearchClear", acPropertyVisible, "-1"
650           DoCmd.GoToControl "SearchBox"
660           DoCmd.SetProperty "cmdSearchGo", acPropertyVisible, "-1"
670           DoCmd.SetProperty "iconSearchGo", acPropertyVisible, "-1"
680       End With




    On Error GoTo 0
    Exit Function

Search_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Search, line " & Erl & "."

End Function
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
817 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. DBG 2,301 Reputation points
    2021-03-31T19:18:01.183+00:00

    Just curious, did that code use to work before? What is the purpose of that code? What do you expect CodeContextObject to be?

    0 comments No comments