473,574 Members | 2,260 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a SQL Server Function From Excel VBA

1 New Member
Dear Forum,

As I'm new to VBA, I was hoping you could answer a VBA / SQL Server 2005 Function question for me.

The scenario is this:

I am trying to call a SQL Server 2005 Function from within Excel (as a Function).
So basically, I want my excel user to type into a cell =MyFunction() which will call the SQL Sever 2005 Function.

I have managed to call Stored Procs etc from within Excel VBA, but functions remain a mystery to me. I just cannot seem to assign the returned value correctly.

To further explain, I have created a small sample Function in SQL Server and is posting that code below.



Expand|Select|Wrap|Line Numbers
  2. CREATE FUNCTION dbo.countrecordsnow (
  3. )
  5. AS
  6. BEGIN
  8. declare
  9. @v_count INT,
  10. @v_return INT
  12. BEGIN
  13. select @v_count = COUNT(*) from dbo.ANALYST
  15. set @v_return = @v_count
  16. return (@v_return)
  18. end
  20. END
Aug 2 '10 #1
1 3637
305 Recognized Expert Contributor
use a recordset object to execute your stored procedure and since you have not aliased the count, you would use rs.fields(0)

Good Luck
Aug 3 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Satish Chimakurthi | last post by:
Hi all, My question is surely a basic one, but somehow, I am not able to figure it out. I have a python file "satish.py" as follows: *satish.py* def main(): y()
by: Ken | last post by:
hello, I would to know if it is possible to call an object in a function within a class. Meaning , In a class, A function X calling onto a function Y, and function Y we want one of the two calculation ( eg seconds , out of seconds and minutes) thanks , Ken
by: kumar yogesh via .NET 247 | last post by:
Hello, I want to develop an application to transfer data from sqlserver to excel such that , when we create a workbook in excel ,then we are able to transfer data from SQL Server to excel in away that the first three columns of the table (In SQL Server)move to the First Worksheet of the workbook,the next set ofthree columns moves to the Second...
by: Todd Lu | last post by:
Hi, I have a datagrid that needs to change when the date changes in my text box. If I manually type my date in and tab(postback) , this works fine but when i call a calendar popup window using javascript I can't seem to call the server side function to change my datagrid. I am currently calling my calendar through javascript on my onclick...
by: ukrbend | last post by:
I'm new to Javascript and to html and am trying to make the following code snippet work but it doesn't. It refuses to call the getPage() function and I always get a 404 error. I know the code is getting as far as the iframe section as other parts of the html code work correctly. But it is not executing any code within the getPage() function...
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I can use dlopen/whatever to convert the function name into a pointer to that function, but actually calling it, with the right number of parameters,...
by: Abhishek | last post by:
Hello All I am able to call the function exported by Exe from a dll file im getting the address of the function but whille calling that function im getting access violation Error as bellow my code Function Exported by EXE void __declspec(dllexport) ExeFn() {
by: vinaykumar Maladkar | last post by:
Hi All, I m writing a program in asp.net using C#.net. I m writing a javascript. I have a bookid in javascript and i want to get information about this bookid from server. The result should be collected if javascript itself. How to do this. Thanx.
by: varuns | last post by:
if i need to call a python function from c, i can use PyImport _Import() python-c API. Following code shows calling python function "add1" from python module "def1" int add(int x, int y) { double answer; Py_Initialize(); PyObject *modname, *mod, *mdict, *func, *arg1, *arg2, *args, *rslt; ...
by: Yansky | last post by:
If I have the following function: function foo(){ alert('hi'); } and I don't need to pass any parameters to it, is calling it this way:
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.