VBA Functions in SQL Statement 
Author Message
 VBA Functions in SQL Statement

I am writing a database application in Access and could use some help.

I would like to write a function in VBA that acts like an Oracle
function and can be used in SQL statement.  A trivial example would be a
function that returns a name when given an id.
the query - select name(id) from emps;
the function name is - select name into name_string from table where id
= id_in; return name_string;

If it is possible to do this in VBA, does anyone have an example or a
place to point me for resources?  Specifically how do I pass a value in
from a query and return a value.



Mon, 16 Oct 2000 03:00:00 GMT  
 VBA Functions in SQL Statement

Don,

Quote:
>I would like to write a function in VBA that acts like an Oracle
>function and can be used in SQL statement.  A trivial example would be a
>function that returns a name when given an id.
>the query - select name(id) from emps;
>the function name is - select name into name_string from table where id
>= id_in; return name_string;

>If it is possible to do this in VBA, does anyone have an example or a
>place to point me for resources?  Specifically how do I pass a value in
>from a query and return a value.

First of all, you can probably use dlookup() for this. But in general,
this is the technique:

Public Function GetNameFromID(lngID As Long) As Variant
  GetNameFromID = DLookup("Name", "yourtable", "yourid=" & lngID)
End Function

(Instead of doing dlookup here you could do something more
interesting....)

Then use it in a SQL statement like so:

select GetNameFromID(table1.id) as NameID, ID from table1

-- Jim Ferguson, FMS
   http://www.fmsinc.com



Mon, 16 Oct 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. ADO: VBA function in select statement

2. ADO: VBA function in select statement

3. set variable with an sql statement in VBA

4. Access: Err 2342 in SQL SELECT Statement in VBA

5. SQL Statement in a VBA procedure

6. SQL statement from VBA

7. Access: Err 2342 in SQL SELECT Statement in VBA

8. VBA in Access ... sql statement with querydef

9. Do SQL statements work in VBA?

10. How to execute a SQL statement with VBA ?

11. Parameters from VB6 to ACCESS VBA SQL-statement

12. VBA SQL statement

 

 
Powered by phpBB® Forum Software