-1

I am trying to create a function that can return me the employee name given the employee ID on a shared table but error pops out:

"Runtime Error '3075': Syntax error in string in query expression '[Employee ID] = 'XXXXX' ".

I tried to implement the different answers I found online but I still couldn`t fix it. Below is my code in question.

Function getName() As String
    Dim Name As String
    getName = DLookup("[Employee Name]", "ID Table", "[Employee ID] = '" & getID & "'")
'getID is a function that returns a string and both Employee Name and Employee ID are in the ID Table
End Function
BigBen
  • 46,229
  • 7
  • 24
  • 40
  • it is short text – ark_freight Nov 21 '18 at 02:58
  • I have removing the bracket but the error still exist and the getID function does give me the correct output.. Does the dlookup require the recordset to be opened first? – ark_freight Nov 21 '18 at 03:18
  • Your DLookup syntax is correct. My bet is that the getID function returns a problematic value, for example a value containing single quotes. Try hardcoding a value within the DLookup in order to skip getID altogether, e.g. "[Employee ID] = 'X123'". – Excelosaurus Nov 21 '18 at 05:25
  • Oh you are correct... but based on the msgbox of my getID function I did not see any ' marks – ark_freight Nov 21 '18 at 05:39

1 Answers1

0

Ok I got it. The getID function had some weird symbol behind it that doesn't show itself on the msgbox. getID relied on another global function that extracts the username of the login. Thanks and sorry for the false alarm