Most of times,the spelling cause this kind of problem. Debug this function with fixed varieties like: select DZRxCheckEligible("NCL OR",#2024-01-01#) By the way,Note the module name is also DZRxCheckEligible. Try rename module name to another name like modOne.
MS Access "Undefined function in Expression"
I wrote the below function and am trying to use it in a query but I keep getting an "Undefined function in Expression" error:
Option Compare Database
Option Explicit
Public Function DZRxCheckEligible(Location As String, SurgeryDate As Variant) As Boolean
If Location = "NCL OR" And SurgeryDate < #5/7/2025# Then
DZRxCheckEligible = False
Else
DZRxCheckEligible = True
End If
End Function
Microsoft 365 and Office | Access | For business | Windows
-
Duane Hookom 26,555 Reputation points Volunteer Moderator
2025-10-09T23:12:04.11+00:00 It looks like your module and function share the same name. This is a no-no. That's why must of us old programmers use naming conventions so the Module name would be like modDZRxCheckEligible.
Also, your where condition uses a limited set of fields. I would probably remove the logic from the query and create one or more functions that accept the field names and return an appropriate value. This would be much easier to understand in the future.
3 additional answers
Sort by: Most helpful
-
Karl Donaubauer 2,696 Reputation points MVP2025-10-08T16:32:26.6166667+00:00 Hi,
Where is your function located? In order for it to be found by the query, it must be in a standard module (not e.g. in the module of a form). These are the modules listed in the navigation pane.
Servus
Karl
Access Forever News DevCon
Access-Entwickler-Konferenz AEK 18.+19.10. Nürnberg -
Dora-T 8,520 Reputation points Microsoft External Staff Moderator
2025-10-09T02:39:21.2466667+00:00 Hi @Zhang, De-An
-Update: The issue was resolved by renaming the module to a different name from the function, as confirmed by @Zhang, De-An
Thank you for reaching out to the Microsoft Q&A Forum.As George and Karl mentioned earlier, it would be helpful if you could provide a bit more information:
-Is your function placed in a standard module (listed under the “Modules” section in the Navigation Pane), or is it currently inside a form or report module?
-Could you please open your query in SQL View and share the SQL statement here?
Access normally recognizes Public functions that are defined in standard modules. If the function happens to be located in a form or report module, or if there are any compilation errors in your VBA project, the query might show the “Undefined function in expression” message.
I look forward to hearing from you.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
-
Zhang, De-An 40 Reputation points
2025-10-09T14:28:17.6866667+00:00 Thank you all for your help and patience:
I believe my it is a standard module:
Here is the SQL Coding:
SELECT DISTINCT AllSports.[Patient Name], AllSports.[Last Name], AllSports.DOB, AllSports.MRN, AllSports.CSN, AllSports.Location, AllSports.Surgeon, AllSports.[Resp An Provider] AS Anes, [AllSports]![Discharge Date]-[AllSports]![Surgery Date] AS LOS, AllSports.[Surgery Date], AllSports.[In Room], AllSports.[Out Room], AllSports.[Discharge Date], AllSports.Procedures, AllSports.procCPTCode AS CPT_Bill, AllSports.procICD10Code AS ICD_Bill, AllBlocks.[File Time] AS BlockDate, IIf(Int([AllBlocks]![File Time])<>Int([AllSports]![Surgery Date]) And [AllBlocks].[File Time] Is Not Null,"No","Yes") AS BlockCheck, AllBlocks.[Note Author] AS BlockBy, AllBlocks.Comments, EPIC_Control_Rx.[Order Instant] AS RxTime, EPIC_Control_Rx.[Ordering User] AS RxOrderer, EPIC_Control_Rx.[Order Description], EPIC_Control_Rx.[Administered Med Amount], EPIC_Control_Rx.[Prescribed Quantity], EPIC_Control_Rx.[Owning Pharmacy], AllSports.[Dosing Weight], InPtOpioidBenzo.[Order Name], IIf((Int([InPtOpioidBenzo]![Administration Instant])<=Int([AllSports]![Discharge Date]) And Int([InPtOpioidBenzo]![Administration Instant])>=Int([AllSports]![Surgery Date])) Or [InPtOpioidBenzo]![Administration Instant] Is Null,"Yes","No") AS DuringStay, InPtOpioidBenzo.[Administration Instant], InPtOpioidBenzo.Route, InPtOpioidBenzo.[Ordering User], InPtOpioidBenzo.[Administering User], InPtOpioidBenzo.[Administered Dose Amount], InPtOpioidBenzo.[Administered Dose Unit], InPtOpioidBenzo.MedicationName, InPtOpioidBenzo.MedType, DZRxCheckEligible([AllSports]![Location],[AllSports]![Surgery Date]) AS RxCheck FROM ((AllSports LEFT JOIN EPIC_Control_Rx ON AllSports.MRN = EPIC_Control_Rx.MRN) LEFT JOIN AllBlocks ON AllSports.MRN = AllBlocks.MRN) LEFT JOIN InPtOpioidBenzo ON AllSports.MRN = InPtOpioidBenzo.MRN WHERE ((([AllSports]![Discharge Date]-[AllSports]![Surgery Date])=1 Or ([AllSports]![Discharge Date]-[AllSports]![Surgery Date])=0) AND ((IIf(Int([AllBlocks]![File Time])<>Int([AllSports]![Surgery Date]) And [AllBlocks].[File Time] Is Not Null,"No","Yes"))="Yes") AND ((IIf((Int([InPtOpioidBenzo]![Administration Instant])<=Int([AllSports]![Discharge Date]) And Int([InPtOpioidBenzo]![Administration Instant])>=Int([AllSports]![Surgery Date])) Or [InPtOpioidBenzo]![Administration Instant] Is Null,"Yes","No"))="Yes"));