LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
ina ina is offline
external usenet poster
 
Posts: 120
Default Problem with sql statement in vba

Hello all,

I have a problem with a sql statement in vba here is my code and I do
not know why because the same query in sql server works file and the
params strRoom is well get through my function

The sub that call this function i do like this:
strRoom = GetroomNumber(cndb, strRoomCode)

Option Explicit

' Description : Get Currency from Index
' Params : the strAssetCode as argument (index InternalCode)
' Returns : an array as String
' Author : RI
' Last Update : 11.05.06


Public Function GetRoomNumber(ByVal cndb As ADODB.Connection,
strRoomCode As String) As String
On Error GoTo GetRoomNumber_Err

Dim strSQL As String 'String for SQL statement
Dim rsroom As ADODB.Recordset 'Recorset


'Set a new recorset
Set rsRoom = New ADODB.Recordset


'SQL statement
strSQL = "SELECT CURRENCY FROM INDEXCURRENCY WHERE INTERNALCODE= '" &
strRoomCode & " '"


Debug.Print strSQL 'I can see the query and if I use the SQL it works

'Recorset and Connection
rsRoom.ActiveConnection = cndb
rsRoom.Open strSQL


GetRoomNumber = rsRoom.Fields(1).Value 'GetRoom = room number

'close the recorset
rsRoom.Close
Set rsRoom = Nothing
Exit Function

GetRoomNumber_Err:
GetRoomNumber = CVErr(xlErrNA)
Exit Function

End Function

 
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
IF statement problem Ross Excel Discussion (Misc queries) 6 July 13th 06 04:47 PM
Still having problem with IF-Then statement excelnut1954 Excel Programming 3 December 18th 05 01:55 AM
IF STATEMENT PROBLEM Manjit Gosal Excel Worksheet Functions 4 November 10th 05 05:40 PM
If Statement Problem TB via OfficeKB.com Excel Worksheet Functions 2 June 29th 05 10:03 PM
I have an "IF"Statement problem...please help!! cmk0007 Excel Worksheet Functions 1 November 5th 04 01:24 AM


All times are GMT +1. The time now is 09:44 AM.

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

About Us

"It's about Microsoft Excel"