Solved

How Do I Get / Set The Value of  MultiValued Field / ComboBox in Visual Basic for Applications Under Access 2007?

Posted on 2009-06-29
9
770 Views
Last Modified: 2013-11-28
Before updating the text field to a multi-value field / combo box, I was using:

 Me.<Textbox Name>.Value = <Value> to set the value

and
Me.<Textbox Name>.Value  to retrieve the value

After updating this field to a multi-value field, the above code no longer works. I've looked at all of the properties and consulted the help menu.  The help menu mentions using DAO to retrieve the parent recordset and then setting a childrecordset to the multivalue field in the parent recordset to browse the selected value.  I've been successful in doing that, but how do I set with vba which values I want selected in the child recordset and how would I pass this back in the parent recordset for submission to the database?
Here is how I would browse the value of the field and this works:
Dim db As DAO.Database
Dim rs As Recordset
Dim childRS As Recordset
 
Set db = CurrentDb
 
' Get Primary RecordSet Note
Set rs = db.OpenRecordset("SELECT * FROM Notes WHERE Note_ID = " & Me.Note_ID)
 
rs.MoveFirst
Set childRS = rs.Fields("Code").Value
 
childRS.MoveFirst
 
Do Until childRS.EOF
MsgBox (childRS.Fields("Value").Value)
childRS.MoveNext
Loop

Open in new window

0
Comment
Question by:davysouthernboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 
LVL 44

Assisted Solution

by:GRayL
GRayL earned 350 total points
ID: 24738539
Look at the property ItemsSelected.  When you selected multiple rows the row numbers are stored in a zero based array called Items Selected.  Help has some good examples in 2003 for multi-select list boxes - I imagine similar for these new Combo boxes in A2007.
0
 

Author Comment

by:davysouthernboy
ID: 24739142
GRayL,  I looked at the ItemSelected property and wrote this code:

Dim CodeCount As Integer
For CodeCount = 0 To Code.ItemsSelected.Count - 1
MsgBox ("Item: " & Code.ItemsSelected.Item(CodeCount))
MsgBox ("Value: " & Code.ItemData(Code.ItemsSelected.Item(CodeCount)))
Next CodeCount

The Code.ItemSelected.Item(CodeCount) line correctly returns the row of the selected item.

However, the line Code.ItemData(Code.ItemsSelected.Item(CodeCount))) returns a blank / empty string everytime.

What am I doing wrong?
0
 
LVL 44

Accepted Solution

by:
GRayL earned 350 total points
ID: 24740982
The format for this is:

forms!frmName!cboName.column(0,forms!frmName!cboName.ItemsSelected(CodeCount))

If you want the second column of the combo, set the 0 to 1.  If you are calling the routine from within the code module of the form, you can replace 'forms!frmName!' with 'Me!'
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:davysouthernboy
ID: 24741226
GrayL, Thank you!  That worked like a charm.  So now I know how to get the values of the selected items in VBA.  Could you please tell me how I could programatically set which values in the combobox are selected in VBA?
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 150 total points
ID: 24743718
If it's anything like listboxes, you will have to select items by the "Row" number.

Something like this:
Me.List0.Selected(2) = True
Me.List0.Selected(5) = True

JeffCoachman
0
 

Author Comment

by:davysouthernboy
ID: 24745246
I put both

Me.Code.Selected(2) = True

and

Me!Code.Selected(2) = True

but it did not work.
Any other ideas?  What's the difference between putting an exclamation mark and a period by the way?
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 150 total points
ID: 24746114
< What's the difference between putting an exclamation mark and a period by the way?>

You could debate this for days.
Basically the Exclamation point (Bang) is used to list the "Members" of an object.
The Period (Dot) is used to list properties.
Many times they are interchangeable.

Is this a listbox, Combobox, or some sort hybrid that is only available in Access 2007?
Be very careful when jumping to use these new Multi-Valued-Fields:
http://allenbrowne.com/Access2007.html#Mixed
(Please remember that database have been designed for decades without the use of this "MS Access olny" feature.)
And that they mask and or limit your abilty to design versitile database designs.
(just be carefull)

JeffCoachman
0
 
LVL 44

Assisted Solution

by:GRayL
GRayL earned 350 total points
ID: 24746319
! - something you made
. - something M$ made.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24752567
Thanks Ray, I had forgotten about your little poem.

;-)
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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