Results 1 to 8 of 8

Thread: VB script - Fill combo box from access db

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Location
    Attard Malta
    Posts
    4

    Unhappy VB script - Fill combo box from access db

    Hi guys. This is my first time so here goes. I am coding forms using VB script on Outlook 2000. I am trying to populate this combobox from an access database. The problems is that the query that i am running by code is giving me dublicate results.

    ex:

    Data: Paul
    Paul
    Mark
    Robert

    I want to display all the names BUT i do not want to display dublicate names.

    The coding i am using is this:
    VB Code:
    1. Public Sub FillSenderCMBSearch()  
    2.     Dim rst         'Recordset
    3.     Dim OBJdbConnection 'Database Connection
    4.     Dim objInsp         'Inspector object
    5.     Dim objApp          'Application Object
    6.     Dim objItem             'Item Object
    7.     Dim objNS           'Namespace Object
    8.     Dim SendersArray
    9.     Dim ArrayIndex
    10.  
    11.         'Fill Senders List
    12.         set OBJdbConnection = CreateObject("ADODB.Connection")
    13.         Set oPage = Item.GetInspector.ModifiedFormPages("Search")
    14.         Set oCtrl = oPage.Controls("cmbSender")
    15.         oCtrl.ColumnCount = 2
    16. '       oCtrl.ColumnWidths = "1;0"
    17. '       oCtrl.BoundColumn = 2
    18.    
    19.         'get length of array by counting number of records
    20.        
    21.         OBJdbConnection.open "Driver=Microsoft Access Driver (*.mdb); dbq= \\fms-server\scanning\E.D.M.S\Database_File\Postdb.mdb"
    22.         set rst = CreateObject("ADODB.Recordset")
    23.         rst.ActiveConnection = OBJdbConnection
    24.         rst.CursorType = 2
    25.         rst.LockType = 2
    26.         rst.source = "SELECT Count(T_Post_Details.ContID) AS CountOfContID FROM T_Post_Details;"
    27.         rst.open
    28.             Redim SendersArray(CInt(rst.fields("CountOfContID")),2)
    29.         rst.close
    30.         OBJdbConnection.Close
    31.         SendersArray(0,0) = ""
    32.         SendersArray(0,1) = "----"
    33.    
    34.         ArrayIndex = 1
    35.  
    36.         OBJdbConnection.open "Driver=Microsoft Access Driver (*.mdb); dbq= \\fms-server\scanning\E.D.M.S\Database_File\Postdb.mdb"
    37.  
    38.         set rst = CreateObject("ADODB.Recordset")
    39.         rst.ActiveConnection = OBJdbConnection
    40.         rst.CursorType = 2
    41.         rst.LockType = 2
    42.         rst.source = "Select ContFileAs, ContID from [T_Post_Details]"
    43.         rst.open
    44.             do while not rst.eof
    45.                 SendersArray(ArrayIndex,0) = rst.fields("ContFileAs")
    46.                 SendersArray(ArrayIndex,1) = rst.fields("ContID")
    47.                 ArrayIndex = ArrayIndex+1
    48.                 rst.movenext
    49.             loop
    50.         rst.close
    51.         OBJdbConnection.Close
    52.         oCtrl.List() = SendersArray
    53.     'Clearing objects to relase memory
    54.     Set objNS = Nothing
    55.     Set objApp = Nothing
    56.     Set oOlFolder = Nothing
    57.     Set oNamespace = Nothing
    Edit: Added vbcode tags for clarity - Hack
    Last edited by Hack; May 13th, 2005 at 05:52 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width