Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default linking a listbox to sql table


hey,

I'm trying to get a listbox on my form to display query results from
SQL server that I have connected to via VBA. Any suggestions? thanks in
advance.


--
marky88
------------------------------------------------------------------------
marky88's Profile: http://www.excelforum.com/member.php...o&userid=37538
View this thread: http://www.excelforum.com/showthread...hreadid=571787

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default linking a listbox to sql table

marky88 wrote:
hey,

I'm trying to get a listbox on my form to display query results from
SQL server that I have connected to via VBA. Any suggestions? thanks in
advance.




Function GetList() As Variant
GetList = Array()
Dim RecordsIdx As Integer
Dim Records() As String
RecordsIdx = 0
Dim DBRst As New ADODB.Recordset
DBRst.Open "select key, v1,v2 from Table", conString, adOpenStatic,
adLockReadOnly
ReDim Records(DBRst.RecordCount - 1, 2)
While DBRst.EOF = False
Records(RecordsIdx, 0) = DBRst!key
Records(RecordsIdx, 1) = DBRst!v1
Records(RecordsIdx, 2) = DBRst!v2
RecordsIdx = RecordsIdx + 1
DBRst.MoveNext
Wend
DBRst.Close
Set DBRst = Nothing
If RecordsIdx = 0 Then Exit Function
GetList = Records
End Function

-----------------------

and now

listbox.List = GetList()



1. conString is a connectionString. It can be global string, function etc.

2. you can play with number of columns in listbox etc, by changing
propierties in listbox, and modyfiing redim instruction.


3. I wrote it from memory, so check errors.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default linking a listbox to sql table


thanks...how would you convert the Access syntax to SQL SERVER 2000
syntax ?


--
marky88
------------------------------------------------------------------------
marky88's Profile: http://www.excelforum.com/member.php...o&userid=37538
View this thread: http://www.excelforum.com/showthread...hreadid=571787

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default linking a listbox to sql table

marky88 wrote:
thanks...how would you convert the Access syntax to SQL SERVER 2000
syntax ?


writing once again from sratch ? :)
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
VBA: Creating listbox similar to the one in Pivot table (Listbox+Checkbox) modjoe23 Excel Programming 3 August 18th 05 02:35 PM
Linking a table in Access to a table in Excel using MS Query Diana[_5_] Excel Programming 1 January 16th 04 09:43 PM
Linking Cells to ListBox - How? William C. Smith Excel Programming 2 December 29th 03 10:53 PM
Select from table and listbox PawelR Excel Programming 1 November 7th 03 01:21 PM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM


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