Using a function to get a value from the database

  • Thread starter Thread starter Craig
  • Start date Start date
C

Craig

I am new to Access but not to .NET. I am trying to learn the Access way of
doing this.

I want to retrieve a value from the database using a function that I can
call from anywhere

How do I do it?

Example

Function fGetEmailAddress(pProfileID)
'Based on the param pProfileID go get the email address from the
database
'Retrieve the data and pass back the email address

'HOW???

End function
 
I am new to Access but not to .NET. I am trying to learn the Access way of
doing this.

I want to retrieve a value from the database using a function that I can
call from anywhere

How do I do it?

Example

Function fGetEmailAddress(pProfileID)
'Based on the param pProfileID go get the email address from the
database
'Retrieve the data and pass back the email address

'HOW???

End function

Such a function already exists: DLookUp. You can call it from
fGetEmailAddress or use it directly:

DLookUp("", "[tablename]", "[ProfileID] = " & pProfileID)
 
That worked! Thanks!!

But I read somewhere that if there are a lot of records, it becomes slow,
correct?????



John Vinson said:
I am new to Access but not to .NET. I am trying to learn the Access way of
doing this.

I want to retrieve a value from the database using a function that I can
call from anywhere

How do I do it?

Example

Function fGetEmailAddress(pProfileID)
'Based on the param pProfileID go get the email address from the
database
'Retrieve the data and pass back the email address

'HOW???

End function

Such a function already exists: DLookUp. You can call it from
fGetEmailAddress or use it directly:

DLookUp("", "[tablename]", "[ProfileID] = " & pProfileID)
[/QUOTE]
 
That worked, but if I had 500,000 records and needed to get a value

In .NET I create a component that does database functions.
Then from a function I create an instance of that component
Feed it the necessary parameters and it returns the appropriate result

How would I do this in Access???





John Vinson said:
I am new to Access but not to .NET. I am trying to learn the Access way of
doing this.

I want to retrieve a value from the database using a function that I can
call from anywhere

How do I do it?

Example

Function fGetEmailAddress(pProfileID)
'Based on the param pProfileID go get the email address from the
database
'Retrieve the data and pass back the email address

'HOW???

End function

Such a function already exists: DLookUp. You can call it from
fGetEmailAddress or use it directly:

DLookUp("", "[tablename]", "[ProfileID] = " & pProfileID)
[/QUOTE]
 
That worked, but if I had 500,000 records and needed to get a value

In .NET I create a component that does database functions.
Then from a function I create an instance of that component
Feed it the necessary parameters and it returns the appropriate result

How would I do this in Access???

I'd use the tools that Access provides. You don't need to attach your
own wheels when you buy a Toyota sedan!

Simply open a Recordset using appropriate criteria. If you have
indexes on the fields that you're using for criteria, performance
should be good using either the Recordset or the DLookUp; the DLookUp
function gets inefficient if you call it multiple times (for instance
if you call it for every record in a table).
 
Back
Top