Solved

Getting info from a string in a listbox

Posted on 1998-10-09
3
129 Views
Last Modified: 2010-04-30
Say there are multiple strings of information in a list box with a person's first name then last name then phone number in that order, and there is a button next to the list box that should only get the selected person's first name from the string and stores it in a global variable. How do you code the button so this occurs?
0
Comment
Question by:Gardiun
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
waty earned 50 total points
ID: 1439061
you should separate each item with a character :

ex :
 cbCombo.Add sFirstName & ";" & sLastName & ";" & sPhone

or

 cbCombo.Add sFirstName & vbTab & sLastName & vbTab & sPhone


in the command button, do as follow :

 sLine = cbCombo.List(cbCombo.ListIndex)
 nPos = Instr(sLine , ";") ' or nPos = Instr(sLine , vbTab)
 sFirsName = Left(sLine , 1, nPos-1)

0
 

Author Comment

by:Gardiun
ID: 1439062
It has a problem with this line:
sFirsName = Left(sLine , 1, nPos-1)

The message read "wrong number of arguments or invalid property assignment." What did you declare nPos as?
0
 
LVL 14

Expert Comment

by:waty
ID: 1439063
Dim sFirsName as String
dim sLine as String
dim nPos  as long
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now