Hi, i am playing around with some functions related to an earlier post about domain functions. anywho: i wrote the following thing as a sorta DLookup replacement figuring that i might learn something simple along the way.
i put:
MyLookUp("Last","tblDemographics","SSN = 'XXXXXXXX'")
in the Immediate window to test and got nothing, but the "Compile Error: Expected: =" message. i commented out everything except for a debug.print("1") line, and still got this error. any thoughts??
i put:
MyLookUp("Last","tblDemographics","SSN = 'XXXXXXXX'")
in the Immediate window to test and got nothing, but the "Compile Error: Expected: =" message. i commented out everything except for a debug.print("1") line, and still got this error. any thoughts??
Code:
Function MyLookUp(fldName As String, tblName As String, condition As String) As String
Dim strQuery As String
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
strQuery = "Select " & fldName & " From " & tblName & " Where " & condition
Debug.Print (strQuery)
With rst
Set .ActiveConnection = CurrentProject.Connection
.CursorType = adOpenKeyset
.Open strQuery
End With
Debug.Print ("1") '(rst.Fields(fldName).Value)
MyLookUp = rst.Fields(fldName).Value
rst.Close
Set rst = Nothing
End Function