Results 1 to 8 of 8

Thread: VB script - Fill combo box from access db

  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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB script - Fill combo box from access db

    Welcome to the Forums.

    I have moved your question from the CodeBank to the VBA forum.

    Thank you for joining our community.

  3. #3
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: VB script - Fill combo box from access db

    Did you try SELECT DISTINCT?
    Tengo mas preguntas que contestas

  4. #4

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

    Re: VB script - Fill combo box from access db

    In my SQL statement?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB script - Fill combo box from access db

    Quote Originally Posted by Powell
    In my SQL statement?
    Yes, SELECT DISTINCT is SQL Code, and instructs the database to return only one item if there are more then one that match the remaining SELECT criteria.

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: VB script - Fill combo box from access db

    e.g., SELECT DISTINCT fldFoo FROM tblGoo.
    If there are two records in tblGoo where fldFoo = "foobar", only one instance of "foobar" will be returned.
    szalamny, another member, is an SQL guru, & doesn't like DISTINCT, forget why, but in a case like this it seems tailor made.
    Last edited by salvelinus; May 13th, 2005 at 09:11 AM.
    Tengo mas preguntas que contestas

  7. #7

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

    Re: VB script - Fill combo box from access db

    10x mate ill give it a try!!!!

  8. #8

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

    Thumbs up Re: VB script - Fill combo box from access db

    It worked perfectluy guys!! thanks for yuor help and for your time.

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