Solved

MS Access VBA Listbox

Posted on 2013-05-15
6
764 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
[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
  • 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 27

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 27

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

751 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