?
Solved

How do I return associated values from selected values in a DataCombo control?

Posted on 2006-05-31
5
Medium Priority
?
170 Views
Last Modified: 2010-04-30
I have a table with the following data:

desc           id       code
-----------  ------     -----
officer         3         off
manager     2         mgr
employee    1         emp

I have a datacombo control called dcStaff and the ListField property is set to desc.

How do I return the code associated to the desc the user selects?

Please show example...

0
Comment
Question by:seckel
5 Comments
 
LVL 13

Assisted Solution

by:Mark_FreeSoftware
Mark_FreeSoftware earned 750 total points
ID: 16798857

add a combobox to your testapp, and paste this code:

Option Explicit

'desc           id       code
'-----------  ------     -----
'officer         3         off
'manager         2         mgr
'employee        1         emp
Private Type DescCode
   Desc As String
   code As String * 3
End Type

Dim d(1 To 3) As DescCode

Private Sub Combo1_Click()
Dim n As Long
   For n = 1 To 3
      If d(n).Desc = Combo1.Text Then
         MsgBox "Code: " & d(n).code & vbCrLf & "id: " & n
      End If
   Next
End Sub

Private Sub Form_Load()
d(3).Desc = "officer"
d(2).Desc = "manager"
d(1).Desc = "employee"
d(3).code = "off"
d(2).code = "mgr"
d(1).code = "emp"
Combo1.AddItem d(3).Desc
Combo1.AddItem d(2).Desc
Combo1.AddItem d(1).Desc
End Sub
0
 

Author Comment

by:seckel
ID: 16800478
Mark_FreeSoftware

You have a good approach, but I'm looking for a way to bind a control to a database table.

I would have to manually code for each record.  Ok, if I have a small table, like the example, but tedious if I want to use a table with hundreds of records.

Do you have any other suggestions?
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16800676

sorry i'm not into databases

(i really need to learn that)


however i can give you a link on database with combobox:

http://www.freevbcode.com/ShowCode.Asp?ID=182
0
 
LVL 6

Expert Comment

by:junglerover77
ID: 16803794
Just set

DataCombo1.DataField = "code"
0
 
LVL 28

Accepted Solution

by:
Ark earned 750 total points
ID: 16805376
rstStaff.Bookmark = dcStaff.SelectedItem
Debug.Print rstStaff("id"),rstStaff("code")
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question