Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Error while populating a combobox from Access database

oForm.Controls(oList).AddItem rs.Fields(1).Value
'Or Fields(0), can't remember if it's 0 or 1 based.

NickHK

"shivboy" wrote in
message ...

Hi,

I coded the following Sub to populate a combobox / listbox but it is
generating a Type mismatch error.


Code:
--------------------

Sub fillBox(ByVal oForm As Form, ByVal oList As Object, ByVal oField As

String, ByVal oTab As String)

dbPath = "C:\abc.mdb"

Dim sql As String

sql = "SELECT " & oField & " FROM " & oTab

Set con = New ADODB.Connection
With con
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open dbPath
End With

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseServer
rs.Open Source:=sql, ActiveConnection:=con,

CursorType:=adOpenForwardOnly, LockType:=adLockOptimistic,
Options:=adCmdText

Do Until rs.EOF
oForm.Controls(oList).AddItem rs(1)
rs.MoveNext
Loop
rs.Close
con.Close
End Sub

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


When I call the above Sub, I use the following code:


Code:
--------------------

Call fillBox(myForm, myCombo, "sName", "tblState")

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


Now, where exactly am I going wrong? Please help.

Peace,

Shivboy


--
shivboy
------------------------------------------------------------------------
shivboy's Profile:

http://www.excelforum.com/member.php...o&userid=35137
View this thread: http://www.excelforum.com/showthread...hreadid=556821



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
Populating a ComboBox DirInfo Excel Programming 1 March 17th 05 10:03 PM
Excel error while trying to import data from an Access database - MSQRY32.exe has generated errors X_HOBBES Excel Discussion (Misc queries) 0 March 15th 05 06:46 PM
Excel VBA Access Database Error Ryan Excel Programming 0 July 8th 04 01:33 PM
Populating combobox/listbox Torstein S. Johnsen[_2_] Excel Programming 1 May 13th 04 09:26 AM
populating a combobox on a worksheet Tim Marsh[_2_] Excel Programming 2 November 3rd 03 12:44 PM


All times are GMT +1. The time now is 01:16 PM.

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"