Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Calling a function in my SQL-DB from VBA

I have made this function in my SQL-DB:

ALTER FUNCTION dbo.KSO_EXL_DKKLandAar
/* Bruges til integration med EXCEL */
(
@Land nvarchar(20),
@Aar int
)

RETURNS money AS

BEGIN

DECLARE @DKK money
SET @DKK =(
SELECT SUM(dbo.CUSTTRANS.AMOUNTCUR * dbo.CUSTTRANS.EXCHRATE
- dbo.CUSTTRANS.VATAMOUNT) AS Oms
FROM dbo.CUSTTRANS INNER JOIN
dbo.CUSTTABLE ON dbo.CUSTTRANS.ACCOUNT =
dbo.CUSTTABLE.ACCOUNT INNER JOIN
dbo.COUNTRY ON dbo.CUSTTABLE.COUNTRY
= dbo.COUNTRY.COUNTRY
WHERE (dbo.CUSTTRANS.DATASET = 'DAT')
AND (dbo.CUSTTABLE.DATASET = 'DAT')
AND (dbo.CUSTTABLE.COUNTRY = @Land)
AND (YEAR(dbo.CUSTTRANS.DATE_) = @Aar)
AND (dbo.CUSTTRANS.TRANSTYPE = 1 OR
dbo.CUSTTRANS.TRANSTYPE = 2)
AND (LEFT(RTRIM(LTRIM(dbo.CUSTTRANS.ACCOUNT)), 1) < '0')

GROUP BY dbo.COUNTRY.DATASET
HAVING (dbo.COUNTRY.DATASET = 'DAT')
)
RETURN @DKK
END

And I want to call this function from Excel VBA - I tried this:


Function C5_LandAar(Land As String, Aar As Integer) As Double
Dim rs As ADODB.Recordset
Dim strSql As String
strSql = "Select dbo.KSO_EXL_DKKLandAar(" & Land & ", " & Aar & ")"
rs.Open strSql, XXXXXXXXXXXXX
If rs.EOF = False Then
C5_LandAar = rs(0)
End If
rs.Close
Set rs = Nothing
End Function

but nothing comes back to the cell.

What is wrong here ?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling worksheet function from a macro Joe Farruggio Excel Worksheet Functions 3 November 20th 06 10:01 PM
Calling function from a userform Jeff Excel Discussion (Misc queries) 0 September 27th 06 03:27 PM
Calling a function and then returning CLamar Excel Discussion (Misc queries) 4 June 19th 06 06:47 PM
Calling an Add-In BillCPA Excel Discussion (Misc queries) 2 August 11th 05 09:32 PM
calling a new function Excel gives me #NAME? Mark Dvorkin Excel Worksheet Functions 4 July 10th 05 01:29 AM


All times are GMT +1. The time now is 07:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"