K
kirk Wilson
Listed below is a public function that is supposed to fetch a text
string based upon an index value. The function compiles without a
problem. When I tested it in the immediate window I get the following
run time error:
Compile error:
Expected: expression
I have no idea what the problem is. Any advice will be apprecisted.
Public Function LookupValue(strTableName As String, strKeyField As _
String, strLookupField As String, bytKeyValue As Byte) As String
Dim rstRecordset As ADODB.Recordset
Dim strCriteria As String
Set rstRecordset = New ADODB.Recordset
strCriteria = strKeyField & "=" & bytKeyValue
With rstRecordset
Set .ActiveConnection = CurrentProject.Connection
.Source = strTableName
.CursorLocation = adUseServer
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
.Find strCriteria
LookupValue = .Fields("Type")
End With
rstRecordset.Close
Set rstRecordset = Nothing
End Function
--------------------------------------------------------------------
tblPhoneType
Recid# = autonumber / primary key / indexed no duplicates
Type = Text * 20
Recid# Type
1 Primary Phone
2 Work Phone
3 Work Fax
4 Pager
5 Cell
----------------------------------------------------------------------
Immediate Window
?lookupvalue(tblphonetype,recid#,type,4)
Run time error
Compile error:
Expected: expression
string based upon an index value. The function compiles without a
problem. When I tested it in the immediate window I get the following
run time error:
Compile error:
Expected: expression
I have no idea what the problem is. Any advice will be apprecisted.
Public Function LookupValue(strTableName As String, strKeyField As _
String, strLookupField As String, bytKeyValue As Byte) As String
Dim rstRecordset As ADODB.Recordset
Dim strCriteria As String
Set rstRecordset = New ADODB.Recordset
strCriteria = strKeyField & "=" & bytKeyValue
With rstRecordset
Set .ActiveConnection = CurrentProject.Connection
.Source = strTableName
.CursorLocation = adUseServer
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
.Find strCriteria
LookupValue = .Fields("Type")
End With
rstRecordset.Close
Set rstRecordset = Nothing
End Function
--------------------------------------------------------------------
tblPhoneType
Recid# = autonumber / primary key / indexed no duplicates
Type = Text * 20
Recid# Type
1 Primary Phone
2 Work Phone
3 Work Fax
4 Pager
5 Cell
----------------------------------------------------------------------
Immediate Window
?lookupvalue(tblphonetype,recid#,type,4)
Run time error
Compile error:
Expected: expression