An expression you entered is the wrong data type for one of the arguments

I have created a form called frmContactCategoryFilter which lists ContactCategory in an unbound box
When the user selects a ContactCategory and clicks OK, frmContact is opened showing only records which have the same ContactCategoryID as the selection
The 'OK' button has the following code

    Dim DocName As String
    Dim LinkCriteria As String

    DocName = "frmContact"
    LinkCriteria = "[ContactCategoryID] = Forms![frmContactCategoryFilter]![lstContactCategory]"
    DoCmd.OpenForm DocName, , , LinkCriteria
           
And it works.
When frmContact opens, I would like frmContactCategoryFilter to close.

However, whenever I try to add a DoCmd.Close , frmContact opens showing the correct records,
the message "An expression you entered is the wrong data type for one of the arguments" is displayed
and frmContactCategoryFilter remains open.

What should I do?
LudiqueAsked:
Who is Participating?
 
Raynard7Connect With a Mentor Commented:
Try

docmd.Close acForm, Me
0
 
flavoConnect With a Mentor Commented:
I can't see how it works in either case, this line:

    LinkCriteria = "[ContactCategoryID] = Forms![frmContactCategoryFilter]![lstContactCategory]"

Should read:

    LinkCriteria = "[ContactCategoryID] = " &  Forms![frmContactCategoryFilter]![lstContactCategory]

Dave
0
 
LudiqueAuthor Commented:
I changed the line as shown
added     DoCmd.Close acForm, "frmContactCategoryFilter"
And it works.

Thanks Dave.

Steph.
0
 
flavoCommented:
Not a problem, glad to help!

Dave
0
All Courses

From novice to tech pro — start learning today.