Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS Access VBA Listbox

Posted on 2013-05-15
6
Medium Priority
?
784 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 664 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 1336 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 27

Accepted Solution

by:
MacroShadow earned 1336 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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: …

715 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