Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default SQL Query, Embedding a Function Call

Hi, Is there a way to embed a function call in a SQL query? Please see my
code below. This runs fine if I omit the "fnCalculateGrossMargin(
[Master$].PartNum, [Master$].Price) as GrossMargin " portion of the SQL query
but get an error when I try to run it with. fnCalculateGrossMargin is a
fairly complex function that can really only be done using a separate VBA
function call. Thanks in advance.
Best Regards, Dean

CODE
*********************************************
Public Sub rewriteFSFDataToWsht(strMeasConfig As String)
On Error GoTo Err_rewriteFSFDataToWsht

Dim rngTemp As Range
Dim rstData As ADODB.Recordset
Dim strConnection As String
Dim strSQL As String

' Create the connection string.
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\FILEBOX\ProductivityTools\DFTTI.xls;" & _
"Extended Properties=Excel 8.0;"

strSQL = "SELECT ALL " & _
"[Master$].Customer, " & _
"[Master$].PartNum, " & _
"[Master$].Qty AS Quantity, " & _
"fnCalculateGrossMargin( [Master$].PartNum, [Master$].Price) as
GrossMargin " & _
"FROM [Master$] ;"

Set rstData = New ADODB.Recordset
rstData.Open strSQL, strConnection, adOpenForwardOnly, adLockReadOnly,
adCmdText

'verify data were received, if so write to worksheet, if not warn the user
If Not rstData.EOF Then
Worksheets("FSF").Range("A5").CopyFromRecordset rstData
Else
MsgBox "No records returned.", vbCritical
End If

'Clean up object and control variables
rstData.Close
Set rstData = Nothing
Set rngTemp = Nothing

Exit_rewriteFSFDataToWsht:
Exit Sub
Err_rewriteFSFDataToWsht:
MsgBox "sub rewriteFSFDataToWsht " & Err.Description
Resume Exit_rewriteFSFDataToWsht
End Sub
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
Basic query on PRODUCT function... Joe Pettersson Excel Discussion (Misc queries) 3 August 7th 06 07:04 PM
Get External Data - not editable using Query Wizard MargaretBeckbury Excel Discussion (Misc queries) 7 January 17th 06 09:13 AM
how i can call the function reneabesmer Excel Worksheet Functions 2 May 2nd 05 12:13 PM
How to call a function from another workbook Joe Excel Discussion (Misc queries) 4 November 26th 04 03:49 PM
How to resize a comment box, by embedding code into a function? JJ Excel Worksheet Functions 13 November 16th 04 08:44 PM


All times are GMT +1. The time now is 12:33 PM.

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"