|
-
May 13th, 2005, 02:04 AM
#1
Thread Starter
New Member
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:
Public Sub FillSenderCMBSearch()
Dim rst 'Recordset
Dim OBJdbConnection 'Database Connection
Dim objInsp 'Inspector object
Dim objApp 'Application Object
Dim objItem 'Item Object
Dim objNS 'Namespace Object
Dim SendersArray
Dim ArrayIndex
'Fill Senders List
set OBJdbConnection = CreateObject("ADODB.Connection")
Set oPage = Item.GetInspector.ModifiedFormPages("Search")
Set oCtrl = oPage.Controls("cmbSender")
oCtrl.ColumnCount = 2
' oCtrl.ColumnWidths = "1;0"
' oCtrl.BoundColumn = 2
'get length of array by counting number of records
OBJdbConnection.open "Driver=Microsoft Access Driver (*.mdb); dbq= \\fms-server\scanning\E.D.M.S\Database_File\Postdb.mdb"
set rst = CreateObject("ADODB.Recordset")
rst.ActiveConnection = OBJdbConnection
rst.CursorType = 2
rst.LockType = 2
rst.source = "SELECT Count(T_Post_Details.ContID) AS CountOfContID FROM T_Post_Details;"
rst.open
Redim SendersArray(CInt(rst.fields("CountOfContID")),2)
rst.close
OBJdbConnection.Close
SendersArray(0,0) = ""
SendersArray(0,1) = "----"
ArrayIndex = 1
OBJdbConnection.open "Driver=Microsoft Access Driver (*.mdb); dbq= \\fms-server\scanning\E.D.M.S\Database_File\Postdb.mdb"
set rst = CreateObject("ADODB.Recordset")
rst.ActiveConnection = OBJdbConnection
rst.CursorType = 2
rst.LockType = 2
rst.source = "Select ContFileAs, ContID from [T_Post_Details]"
rst.open
do while not rst.eof
SendersArray(ArrayIndex,0) = rst.fields("ContFileAs")
SendersArray(ArrayIndex,1) = rst.fields("ContID")
ArrayIndex = ArrayIndex+1
rst.movenext
loop
rst.close
OBJdbConnection.Close
oCtrl.List() = SendersArray
'Clearing objects to relase memory
Set objNS = Nothing
Set objApp = Nothing
Set oOlFolder = Nothing
Set oNamespace = Nothing
Edit: Added vbcode tags for clarity - Hack
Last edited by Hack; May 13th, 2005 at 05:52 AM.
-
May 13th, 2005, 05:56 AM
#2
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.
-
May 13th, 2005, 06:53 AM
#3
Frenzied Member
Re: VB script - Fill combo box from access db
Did you try SELECT DISTINCT?
Tengo mas preguntas que contestas
-
May 13th, 2005, 08:55 AM
#4
Thread Starter
New Member
Re: VB script - Fill combo box from access db
-
May 13th, 2005, 09:04 AM
#5
Re: VB script - Fill combo box from access db
 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.
-
May 13th, 2005, 09:08 AM
#6
Frenzied Member
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
-
May 13th, 2005, 09:43 AM
#7
Thread Starter
New Member
Re: VB script - Fill combo box from access db
10x mate ill give it a try!!!!
-
May 17th, 2005, 04:49 AM
#8
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|