Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
794 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 1400 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 1400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 600 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 600 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 1400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

650 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