Combo box value?

C

chanley

I have a combo box.
When I open the form, it queries a SQL server and populates two columns in
the dropdown list with the values from the two columns in the database.
The contents of the drop down are successfully populated with data from both
columns. That part is okay.

The problem is that when I make a selection from the list, it only puts the
data from the first column, (and not the second), in the main field. I want
the selection that gets returned to the field to be the same as what is
displayed in the dropdown list.
(forgive the lack of proper terminology, I'm kinda new to this).
It's currently doing this.
http://www.olinptr.com/public/cboexample.jpg


here is my code;
==================
Option Explicit
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adStateOpen = 1

Function Item_Open()
On Error Resume Next
Call FillCompanyList
End Function

Sub FillCompanyList()
Dim m_adoMS
Dim cboprojects
Dim rstprojs
Dim strSQL
Dim objPage
On Error Resume Next
Set m_adoMS = OpenDB()
If Not m_adoMS.State Is Nothing Then
Set objPage = _
Item.GetInspector.ModifiedFormPages("projects")

Set cboprojects = objPage.Controls("cboprojects")

Set rstprojs = CreateObject("ADODB.Recordset")

strSQL = "SELECT [prProject], [prName] " & _
"from PR " & _
"ORDER BY [prProject];"

rstprojs.Open strSQL, m_adoMS, _
adOpenForwardOnly, adLockReadOnly

If rstprojs.State = adStateOpen Then
cboprojects.Column = rstprojs.GetRows
rstprojs.Close
End If

Set rstprojs = Nothing

If m_adoMS.State = adStateOpen Then
m_adoMS.Close
End If

Set m_adoMS = Nothing
Set cboprojects = Nothing
End If
End Sub

Function OpenDB()
Dim objADOConn
Dim strConn
On Error Resume Next
strConn = "Provider=sqloledb;" & _
"Data Source=;" & _
"Initial Catalog=;" & _
"UID=;" & _
"PWD=;" & _
"Network Library=dbmssocn;"
Set objADOConn = CreateObject("ADODB.Connection")
objADOConn.Open strConn
If (Err = 0) And (objADOConn.State = adStateOpen) Then
Set OpenDB = objADOConn
Else
Set OpenDB = Nothing
End If
Set objADOConn = Nothing
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top