Hi,
I have a query that I'm working on through Access 2010's design view. I'd like to add a criteria to the query where it only shows results with the employee name column matching a global variable I created that stores the name of the currently logged in employee.
Here's my vba code that declares the global variable and the public function i'm trying to pass as criteria in the query:
Global gbl_loginName As String
Public Function returnName() As String
If IsNull(gbl_loginName) Then
returnName = "test" ' dummy account created for development only
Else
returnName = gbl_loginName
End If
End Function
and here's the SQL code from Access's design view:
SELECT [Entry of Hours].WC, [Entry of Hours].[Employee Name], [Entry of Hours].[Set Up Time], [Entry of Hours].[Run time], [Entry of Hours].[Traveler Number], [Entry of Hours].[Entry Date],
[Entry of Hours].[Quantity Finished], [Entry of Hours].Notes, [Entry of Hours].WPS, [Entry of Hours].DMR, [Entry of Hours].[Employee Number], Traveler_to_Drawing.Drawing_Number,
Traveler_to_Drawing.Customer, Drawings.Description, Traveler_to_Drawing.Due_Date, [Entry of Hours].[Set Up Time] + [Entry of Hours].[Run time] AS Total, LEFT([Entry of Hours].[Traveler Number],
6) AS WO
FROM [Entry of Hours] INNER JOIN
Traveler_to_Drawing ON [Entry of Hours].[Traveler Number] = Traveler_to_Drawing.Traveler_Number INNER JOIN
Drawings ON Traveler_to_Drawing.Drawing_Number = Drawings.Drawing_Number
WHERE ([Entry of Hours].[Employee Name] = returnName())
when I try running the query, however, I get this error:
'returnName' is not a recognized built-in function name
Can I get some advice on what i'm doing wrong? Is there a problem with using public functions in Access' design view?
Thanks!
I have a query that I'm working on through Access 2010's design view. I'd like to add a criteria to the query where it only shows results with the employee name column matching a global variable I created that stores the name of the currently logged in employee.
Here's my vba code that declares the global variable and the public function i'm trying to pass as criteria in the query:
Global gbl_loginName As String
Public Function returnName() As String
If IsNull(gbl_loginName) Then
returnName = "test" ' dummy account created for development only
Else
returnName = gbl_loginName
End If
End Function
and here's the SQL code from Access's design view:
SELECT [Entry of Hours].WC, [Entry of Hours].[Employee Name], [Entry of Hours].[Set Up Time], [Entry of Hours].[Run time], [Entry of Hours].[Traveler Number], [Entry of Hours].[Entry Date],
[Entry of Hours].[Quantity Finished], [Entry of Hours].Notes, [Entry of Hours].WPS, [Entry of Hours].DMR, [Entry of Hours].[Employee Number], Traveler_to_Drawing.Drawing_Number,
Traveler_to_Drawing.Customer, Drawings.Description, Traveler_to_Drawing.Due_Date, [Entry of Hours].[Set Up Time] + [Entry of Hours].[Run time] AS Total, LEFT([Entry of Hours].[Traveler Number],
6) AS WO
FROM [Entry of Hours] INNER JOIN
Traveler_to_Drawing ON [Entry of Hours].[Traveler Number] = Traveler_to_Drawing.Traveler_Number INNER JOIN
Drawings ON Traveler_to_Drawing.Drawing_Number = Drawings.Drawing_Number
WHERE ([Entry of Hours].[Employee Name] = returnName())
when I try running the query, however, I get this error:
'returnName' is not a recognized built-in function name
Can I get some advice on what i'm doing wrong? Is there a problem with using public functions in Access' design view?
Thanks!