Function to read record by 2 indexes

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
 
S

Stuart McCall

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'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top