Function to read record by 2 indexes

  • Thread starter Thread starter mscertified
  • Start date Start date
M

mscertified

I'd like to set up a function to read a record from a table either by the
primary key (long) or secondary index (text). So I need 2 optional parameters
and depending which is passed, read via the appropriate key.
Can someone give me sample code for processing the optional parameters?
Will this do it?
Private Sub GetData(Optional lngID As Long = 0, Optional strID as string =
"") as boolean
If lngID = 0 Then
....
else
....
end if
end sub
 
mscertified said:
I'd like to set up a function to read a record from a table either by the
primary key (long) or secondary index (text). So I need 2 optional
parameters
and depending which is passed, read via the appropriate key.
Can someone give me sample code for processing the optional parameters?
Will this do it?
Private Sub GetData(Optional lngID As Long = 0, Optional strID as string =
"") as boolean
If lngID = 0 Then
...
else
...
end if
end sub

Yes that'll do it. Quite a simple rule (always good) - If ID provided, use
it and ignore string, otherwise use string. Just what you do to replace the
....'s depends where the code is running and what you want to do with the
data once it's been 'got'.
 
Back
Top