Need help creating User-Defined Functions in Excel to query from a database

Brandont05

New Member
Joined
May 27, 2016
Messages
6
I work in an HR department that does not have any user defined functions(custom functions).

For example: I would like to be able to use an Employee# to pull their First Name from our database.
Example Function: =GetFirstName(Employee#)

I need help writing the VBA coding necessary to facilitate this function.

Function Name: GetFirstName
Database Name: c11e
Data Table: EMPLOYEE
Data Field: FIRST_NAME

I greatly appreciate any help.
 
OK, the only thing you should need to change is the connection string

so this
Rich (BB code):
 sConnString = "Provider=SQLOLEDB;Data Source=YOUR_SERVER_NAME_HERE;" & _
                  "Initial Catalog=c11e;" & _
                  "Integrated Security=SSPI;"

becomes something more like this

Rich (BB code):
sConnString = "Provider=msdaora;Data Source=  (DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = YOUR.SERVER.IP.ADDRESS )(PORT = ####)))" & _
"(CONNECT_DATA =(SERVICE_NAME = c11e)));" & _
"User ID=yourusername;" & _
"Password=yourpassword"
 
Last edited:
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,216,100
Messages
6,128,834
Members
449,471
Latest member
lachbee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top