ACC2002: InputParameter Property Cannot Perform Lookup to Visual Basic for Applications Function (287449)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q287449
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access project (.adp).

SYMPTOMS

When you try to evaluate an input parameter in a function that is referenced in the RecordSource property of a form, the InputParameter property is properly populated. However, you receive the following error message when you open the form and supply a valid input parameter:
Invalid SQL Statement.

Check the server filter on the form record source.

CAUSE

This is a limitation in Microsoft Access. Access performs basic evaluation of object references, but Access does not perform Visual Basic for Applications function evaluation.

RESOLUTION

Set the record source of the form to an SQL statement that accepts parameters, similar to the following:
SELECT * FROM Products WHERE CategoryID = ?
				
You must also set the InputParameter property equal to a reference to the function, similar to the following:
lGetValue()
				

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Access 2002, and then open the sample project NorthwindCS.adp.
  2. Add a new module, and then type or paste the following code:
    Public Function lGetValue()
        lGetValue = 2
    End Function
    					
  3. Save the module.
  4. Open the Products form in Design view. On the Data tab, modify the Recordsource property as follows:
    SELECT * FROM Products WHERE CategoryID = @lGetValue()
    					
  5. Save the form with a new name, and then switch the form to Form view.
  6. When you are prompted for the parameter, enter a value, such as 5. Note that you receive the error message that is mentioned in the "Symptoms" section of this article.

Modification Type:MajorLast Reviewed:11/6/2003
Keywords:kbbug kberrmsg kbnofix KB287449