Solved

MS Access VBA Listbox

Posted on 2013-05-15
6
706 Views
Last Modified: 2013-05-20
I am trying to build two listboxes by using ACCESS 2010. See my attachment please. So far I can load a list of names in the left listbox. What I need to do are:

1). Can select names from the left listbox. (so far the name list cannot be selected)
2). click the arrow button then the selected name(s) can move to the right listbox.  So far I don't have any code. I forgot how to do it.

Can you help me? I am waiting for your directions while trying to figure it out. Thank you.
twoListBoxes.docx
0
Comment
Question by:HopeQ
  • 2
  • 2
  • 2
6 Comments
 
LVL 12

Assisted Solution

by:pdebaets
pdebaets earned 166 total points
ID: 39169450
Your arrow button will need to build an SQL statement and run it. The SQL statement should insert the name into the underlying row source of the second list box, then requery it to display the results. The exact text of the SQL statement might depend on what the row sources of the two list boxes actually are. Here's an example:

Dim strSQL as string

strSQL = ""
strSQL = strSQL & "Insert Into MyTable "
strSQL = strSQL & "    ([Name]) "
strSQL = strSQL & "  Values "
strSQL = strSQL & "     (" & chr(34) & me!MyFirstListBox & chr(34) & ")"
strSQL = strSQL & ";"
currentdb().execute strsql, dbseechanges + dbfailonerror
me!MySecondListBox.requery
0
 
LVL 26

Assisted Solution

by:MacroShadow
MacroShadow earned 334 total points
ID: 39169484
0
 

Author Comment

by:HopeQ
ID: 39169703
Thank you. But I cannot open MacroShadow's code behind the button. It says missing MSDATGRD.OCX version1.0. And I don't know where I should use the code from pdebaets.

I am still waiting for solution. I wanted use the Button-click to write some code to move the selection from left listbox to the right listbox.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 26

Accepted Solution

by:
MacroShadow earned 334 total points
ID: 39169728
0
 
LVL 12

Expert Comment

by:pdebaets
ID: 39169782
You can put the code in your button OnClick event procedure. The code is an example. It really depends on what the row sources are for your two list boxes.
0
 

Author Closing Comment

by:HopeQ
ID: 39181430
Thank you guys.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now