"Function Isn't Available in Expressions..." Error Message
ID: Q194374
|
The information in this article applies to:
-
Microsoft Access 97
-
Microsoft Office Developer Edition 97
Advanced: Requires expert coding, interoperability, and multiuser skills.
SYMPTOMS
When you run a query, you may receive the following error message:
Function isn't available in expressions in query expression.
You may see a "#Name" error on forms and reports in controls that use an
expression for the ControlSource property. This behavior can occur in
forms, queries, or reports that use built-in functions in expressions, for
example, the Format(), Left(), or Right() function.
CAUSE
You developed a database by using a particular version of a type library, and then upgraded the version of the type library on your development computer.
-or-
You referenced a type library on your development computer, and then moved the database to a computer that has a newer version of the type library installed.
NOTE: This issue most frequently involves references to Comctl32.ocx, but can occur with other type libraries. An example of installing a newer type library version is installing newer versions of Microsoft Data Access Components (MDAC). Sometimes the upgrade of a type library is subtle, such as upgrading the operating system version or installing a new application.
RESOLUTION
To fix this problem, you need either the same version of the type
library on your development computer and on other computers that will be
using the database, or you can refresh the reference to the type library
on the computers that will be using the database so that Microsoft Access
recognizes the control. What follows are three methods that you can use to
do this.
Important Note on MDE files: The methods below only work in standard Access files (*.mdb). You cannot refresh references in an Access MDE (*.mde) file. References must be refreshed in the original MDB before being recompiled into a new MDE.
Using Microsoft Access to Refresh a Reference
You can use Microsoft Access to refresh the references on a target
computer manually. To do so, follow these steps:
- Open the database that causes the errors mentioned in the "Symptoms"
section.
- On the Modules tab, click New.
- On the Tools menu, click References.
- In the References dialog box, pick any single reference that is not already selected, click to select it, note which one you selected, and then click OK.
- On the Tools menu, click References again.
- Click to clear the reference that you selected in step 4, and click OK.
- Run the query, form, or report on which you saw the errors mentioned in the "Symptoms" section. No errors occur.
Updating the Distributed Control
You can update the version of the control on your development computer
to match the one on your target computer. After you have updated the
control on your development computer and refreshed the reference to it in
your database (see the "Using Microsoft Access 97 to Refresh a Reference"
section earlier in this article), you can copy the database back onto the
target computer(s).
If you are distributing an application using the Microsoft Office 97
Developer Edition (ODE), you should run the Setup Wizard again to rebuild
the setup files, and then have users reinstall the application.
Automatically Refreshing References by Using Visual Basic for Applications
You can use Visual Basic for Applications code to refresh the references in
your database automatically. This solution uses a query to test for the
problem described by this article, and then runs Visual Basic for
Applications code to refresh the references if the problem exists. If you
are distributing ODE applications, you can include this in both future and
upgrade versions of your application.
- Create a new query in your database to test for the symptoms. The query needs to use one of the built-in Access functions, for example the Format(), Left(), or Right() function. Save the query as qryTestRefs.
For example, using the Northwind database, you could use a query that returns the first letter of the Category Name field in the Category table, as follows:
Query: qryTestRefs
------------------------------
Field: Expr1
------------
Value: Left([Category Name],1)
- Create a macro as follows, and save it as AutoExec:
Macro Name Action
--------------------
AutoExec RunCode
Action Arguments
-------------------------
Function Name: CheckRefs()
- Create the following module, and type or paste the following code into it:
Function CheckRefs()
Dim db As Database, rs As Recordset
Dim x
Set db = CurrentDb
On Error Resume Next
' Run the query qryTestRefs you created and trap for an error.
Set rs = db.OpenRecordset("qryTestRefs", dbOpenDynaset)
' The if statement below checks for error 3075. If it encounters the
' error, it informs the user that it needs to fix the application.
' Error 3075 is the following:
' "Function isn't available in expressions in query expression..."
' Note: This function only checks for the error 3075. If you want it to
' check for other errors, you can modify the If statement. To have
' it check for any error, you can change it to the following:
' If Err.Number <> 0
If Err.Number = 3075 Then
MsgBox "This application has detected newer versions " _
& "of required files on your computer. " _
& "It may take several minutes to recompile " _
& "this application."
Err.Clear
FixUpRefs
End If
End Function
Sub FixUpRefs()
Dim r As Reference, r1 As Reference
Dim s As String
' Look for the first reference in the database other
' than Access and Visual Basic for Applications.
For Each r In Application.References
If r.Name <> "Access" And r.Name <> "VBA" Then
Set r1 = r
Exit For
End If
Next
s = r1.FullPath
' Remove the Reference and add it back.
References.Remove r1
References.AddFromFile s
' Call a hidden SysCmd to automatically compile/save all modules.
Call SysCmd(504, 16483)
End Sub
STATUS
Microsoft has confirmed this to be a problem in Microsoft Access 97.
MORE INFORMATION
When a type library is installed on a computer, specific information about
it is placed in the Windows registry. Microsoft Access uses this registry
information to reference and use the type library. Under normal conditions,
installing a newer version of a type library on a computer has no effect on
the programs that use it, but in some cases, changes to the type
libraries cause them to be registered differently. When this happens,
Microsoft Access can't use them until the new registry information is
refreshed in the References collection.
Steps to Reproduce Problem
- Reformat two test computers.
- Install Microsoft Windows 95 or Microsoft Windows 98 on both
computers.
- On the first computer, install Microsoft Access 97.
- On the first computer, install Microsoft Office 97 Developer
Edition.
- On the first computer, create a new database.
- In the new database, on the Tables tab, click New, and then click
Design View.
- In Design view, create the following new table:
Table: Table1
-------------------------------
Field Name: CategoryID
Data Type: Counter
Indexed: Yes (No Duplicates)
Field Name: CategoryName
Data Type: Text
Field Name: Location
Date Type: Text
Field Size: 20
Indexed: Yes (Duplicates OK)
Table Properties: Table1
------------------------------
PrimaryKey: CategoryID
Index1: CategoryName; Location
- Save the table as Table1 and switch to Datasheet view.
- In Datasheet view, add a few records to the table.
- Create a new query based on the table.
- Add Field1 to the query, as well as the following expression:
EXPR1: Format([CategoryID], " #")
- Save the query as Query1, and then close it. Do not run the query.
- Open a new, blank form in Design view.
- Insert the Microsoft CommonDialog (version 5.0) and the Microsoft
Treeview (version 5.0) controls on the form.
- On the View menu, click Code to see the module of the form. (This
automatically sets the HasModule property to Yes.)
- On the Tools menu, click References, and verify that you have the
following references (in order):
Visual Basic For Applications
Microsoft Access 8.0 Object Library
Microsoft DAO 3.5 Object Library
Microsoft Common Dialog Control 5.0
Microsoft Windows Common Controls 5.0
- On the Debug menu, click Compile And Save All modules. Save the form
as Form1 when prompted.
- Close the form.
- Run the Query1 query and verify that it works correctly.
- Copy the database to a second computer that has version 5.00.4319
or later of COMCTL32.OCX installed. This version of the control can be
obtained with Microsoft Visual Studio 5.0 SP3 or Visual Studio 6.0.
- Open the database on the second computer and run the Query1 query.
Note that you receive the following error message:
Function isn't available in expressions in query expression
'Format([CategoryID], " #")'
Following this, if you change the references in any way, the problem is
resolved. For instance, you can add a reference at random, click OK to
close the References dialog box, and then remove that reference.
REFERENCES
For more information about references, search the Help Index for
"References collection," or ask the Microsoft Access 97 Office Assistant.
Additional query words:
typelib activex pra
Keywords : kberrmsg kbdta IntpCstm OdeGen
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbbug
|