Solved

MS Access VBA Listbox

Posted on 2013-05-15
6
774 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

617 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