Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default ADO Function

Thanks to all. I have learned quite a bit today. The code that follows is the
code that works.

Function GetItemDesc(ItemNumber As String)

Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = "DSN=AS400"
conn.Open
strQuery = "SELECT JFITDS FROM SCDBFP10.USIAJFPF WHERE JFITEM='" &
ItemNumber & "'"
GetItemDesc = conn.Execute(strQuery).Fields(0)

Set conn = Nothing
Set StrConn = Nothing

End Function


"keepITcool" wrote:

your function doesnt return a value.. so you get the #value! error.

try like:

GetItemDesc = conn.Execute(strQuery).Fields(0)

connExecute returns a recordset object..
normally you 's "catch that" like
set oRST = conn.Execute(str)

since your query retrieves 1 field only
i've "piped" it into the string above.
note that the recordset's fields collection is ZERO based!




http://www.devguru.com/Technologies/...ado_intro.html
has very good references for ADO and JetSql




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"?B?RGVhbiBVbmRlcndvb2Q=?="
wrote:

First. Sorry about the double post. Now the code looks like the
following and it still returns a "#VALUE" in the cell. Thanks for the
response. As you can tell I am stumped.

Function GetItemDesc(ItemNumber As String)

Set conn = Server.CreateObject("ADODB.Connection")
strConn = "DSN=AS400"
conn.Open strConn
strQuery = "SELECT USIAJFL0.JFITDS FROM AS400.SCDBFP10.USIAJFL0
WHERE
USIAJFL0.JFITEM='" & ItemNumber & "'"
conn.Execute (strQuery)

End Function


"Harald Staff" wrote:

"Dean Underwood" skrev i
melding ...
I am new to witing VBA and am struggling with writing a function.
The following code does not work. What could be wrong.

strQuery = "SELECT USIAJFL0.JFITDS FROM AS400.SCDBFP10.USIAJFL0
WHERE
USIAJFL0.JFITEM=ItemNumber"

Hi Dean

You are searching for the literal text "ItemNumber", not the variable
value of ItemNumber. Bringing us to

WHERE USIAJFL0.JFITEM=" & ItemNumber

This should work if the JFITEM table is numerical. If it's a text
field however then it needs to be enclosed by single quotes like this

WHERE USIAJFL0.JFITEM='" & ItemNumber & "'"

HTH. Best wishes Harald







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
Excel Data Validation/Lookup function does function correcty Kirkey Excel Worksheet Functions 2 May 25th 09 09:22 PM
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


All times are GMT +1. The time now is 07:22 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"