[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Populate textbox from listbox selections

Posted on 2005-04-18
7
Medium Priority
?
511 Views
Last Modified: 2006-11-18
I am using the following code to populate a Multi-select listbox string into a textbox...

 Dim intCurrentRow
Dim strItems


For intCurrentRow = 0 To List186.ListCount - 1
        If List186.Selected(intCurrentRow) Then
            strItems = strItems & List186.Column(0, _
                 intCurrentRow) & ";"
        End If
    Next intCurrentRow

Me!InholeString.Value = strItems

How can I modify this code to populate a textbox if a Listbox multiselect is set to none? I tried this code but does not populate unless it is set to multiselect.
   
0
Comment
Question by:Sherkanowski
  • 4
  • 3
7 Comments
 
LVL 4

Expert Comment

by:hkang042997
ID: 13809660
You can exit the loop once a selected item is found:

For intCurrentRow = 0 To List186.ListCount - 1
        If List186.Selected(intCurrentRow) Then
            Me!InholeString.Value = List186.Column(0, intCurrentRow)
            Exit For
        End If
Next intCurrentRow

or use the ListIndex property of the list to extract the list item:
Me!InholeString.Value = List186.Column(0, List186.ListIndex)
0
 

Author Comment

by:Sherkanowski
ID: 13809826
still only works if the multiselect is set to simple on the listbox if I set it to none (as needed) it does not fill the text with anything.
0
 
LVL 4

Accepted Solution

by:
hkang042997 earned 2000 total points
ID: 13810056
Try the second method and don't use the For...Next loop at all:

Me!InholeString.Value = List186.Column(0, List186.ListIndex)
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:Sherkanowski
ID: 13810298
That works to populate the textbox but if I try to save a new record with that updated field I get an error...

You can't save this record at this time...

select yes to continue...

another message...

Can't find the macro with quotes around a square box?
0
 
LVL 4

Expert Comment

by:hkang042997
ID: 13810437
I think you'll have to start a new question to resolve the errors.  There are several reasons why you might get the first error message, and you'd have to break down your processes in detail in order for you to get useful help.

In the second error message, do you mean the message says

Can't find macro "x".

where the x is a box that you sometimes see as representing an unprintable character?
0
 

Author Comment

by:Sherkanowski
ID: 13810493
It has something to do with the text fields - I removed the code which updates them and I still get the errors when trying to save a new record with data in any of the textboxes
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…
Suggested Courses

590 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