Solved

MS Access VBA Listbox

Posted on 2013-05-15
6
732 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 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
Back Up Your Microsoft Windows Server®

Back up 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.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

773 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