+ Reply to Thread
Results 1 to 2 of 2

Error while populating a combobox from Access database

  1. #1
    Registered User
    Join Date
    06-06-2006
    MS-Off Ver
    2010, 365
    Posts
    39

    Question Error while populating a combobox from Access database

    Hi,

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

    Please Login or Register  to view this content.
    When I call the above Sub, I use the following code:

    Please Login or Register  to view this content.
    Now, where exactly am I going wrong? Please help.

    Peace,

    Shivboy

  2. #2
    NickHK
    Guest

    Re: 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" <[email protected]> wrote in
    message news:[email protected]...
    >
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1