473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Add item to listbox from a popup form

I am trying to populate data into a listbox using VBA from a popup form.

The main form holds the listbox and the button that opens the second form. I want the user to be able to enter an address into the second form. When the user clicks the close button on the second form, I want to add the data into a new row in the mainforms listbox without writing the data to a table at this stage (this is done later on the collection of other data).

I can not get my references correct in the code of the second form to populate the data into the listbox on the first form.

Any help offered will be appreciated.

Thanks
Aug 29 '10 #1

✓ answered by ADezii

Assuming your 1st Form is named Form1, contains a List Box named List1, your 2nd Form is named Form2, the 2nd Form contains a Text Box named txtValue which contains the Value to be added to the List Box on Form1, Form1 opens Form2 and remains Open, then, in the Close() Event of Form2:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2. Dim lst As ListBox
  3.  
  4. Set lst = Forms!Form1![List1]
  5.  
  6. If Not IsNull(Me![txtValue]) Then
  7.   lst.AddItem Me![txtValue]
  8.   lst.Requery
  9. End If
  10. End Sub

4 4191
ADezii
8,834 Expert 8TB
Assuming your 1st Form is named Form1, contains a List Box named List1, your 2nd Form is named Form2, the 2nd Form contains a Text Box named txtValue which contains the Value to be added to the List Box on Form1, Form1 opens Form2 and remains Open, then, in the Close() Event of Form2:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2. Dim lst As ListBox
  3.  
  4. Set lst = Forms!Form1![List1]
  5.  
  6. If Not IsNull(Me![txtValue]) Then
  7.   lst.AddItem Me![txtValue]
  8.   lst.Requery
  9. End If
  10. End Sub
Aug 29 '10 #2
missinglinq
3,532 Expert 2GB
Note that for ADezii's code to work the RowSourceType has to be set to "Value List." Also, this method is only available in post Access2000 versions. In v2000 and earlier versions AddItem was used to add items to Menus, I believe.

Linq ;0)>
Aug 29 '10 #3
ADezii
8,834 Expert 8TB
Excellent point by Linq. If you are working in an earlier Version (AddItem not supported), and the RowSourceType of the Value List is Value List, then:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2. Dim lst As ListBox
  3.  
  4. Set lst = Forms!Form1![List1]
  5.  
  6. If Not IsNull(Me![txtValue]) Then
  7.   lst.RowSource = lst.RowSource & ";" & Me![txtValue]
  8.   lst.Requery
  9. End If
Aug 29 '10 #4
Thank you ADezii and missingling for your replies. It has worked perfectly.
Aug 30 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Xenophobe | last post by:
I have a popup window (required by the client) containing a form and would like to prevent users from accessing it directly. They are instead required to access the page via a hyperlink on another...
2
by: sramruttun | last post by:
hi I have a popup form with a radiobuttonlist which is populated with data at runtime and upon selection of an item, the item is sent to the parent form. This works Ok. The list of items are...
4
by: SteveS | last post by:
Hello. This is a strange problem which does not make sense to me. I open a popup page with the following javascript code: function OpenDenyWindow(changeId) {...
18
by: Colin McGuire | last post by:
Hi - this was posted last weekend and unfortunately not resolved. The solutions that were posted almost worked but after another 5 days of working on the code everynight, I am not further ahead....
2
by: baret bonden | last post by:
Trying to return a selected listbox item to another form .tried lots of ways; defining public variables and passing those as well as textboxes ..I' m able to display the chosen item on it's form...
13
by: Deano | last post by:
Apparently you can only do this with one value i.e Call MyAssetLocationZoom(Me!txtLocation, "Amend data") This runs; Public Sub MyAssetLocationZoom(ctl As Control, formName As String) On...
4
by: Macbane | last post by:
Hi, I have a 'main' form called frmIssues which has a subform control (named linkIssuesDrug) containing the subform sfrmLink_Issues_Drugs. A control button on the main form opens a pop-up form...
1
by: avni sanghvi | last post by:
i have created popup form in which listbox is used.when clicked on any item in listbox that value should be pass to the parent form for further processing. Please help me urgently thank u in advance
9
by: rousseaud | last post by:
I'm having some trouble getting popup forms to work properly. I have a main form that contains 4 fields that I want to fill in by using a series of 4 popup forms that I initiate by clicking a...
7
by: EManning | last post by:
I have an A2003 database linked to SQL Server 2005. My problem is with a popup form with a filtered table as a recordsource. I set the filter with an SQL statement like this: SELECT * FROM...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.