Solved

getting just a certain part from a listbox

Posted on 2000-04-19
7
197 Views
Last Modified: 2010-05-02
I have a calendar control that fills out orders due on the date that the user clicks. Now what I need is to read just the order number (6 digits) from the list box once the user selects which one they want to use so I can fill out a different form.
0
Comment
Question by:doctorlove
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:Sage020999
ID: 2732164
what format is the information in?  Is it pipe delimited.  If so you can use the split statement to break up the list box into an array varible if you are using VB6.  If not you will have to parse the text.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2732225
doctorlove writes: "from the list box once the user selects which one they want to use"

Once the user clicks on an item in a listbox, the listbox item is placed into the Text property. Eg.

Private Sub List1_Click()

   Dim strOrderNo as String
   strOrderNo = List1.Text

End Sub
0
 

Author Comment

by:doctorlove
ID: 2732446
Sage: Guess I'm confused as to what you mean by pipe delimited. :/

Here's my code right now:

    sPath = App.Path & "\clients.mdb"
    Set daoDB36 = DBEngine.OpenDatabase(sPath)
    Set rs = daoDB36.OpenRecordset("customers")
   
    List1.Clear
    rs.MoveFirst
    Do Until rs.EOF
        If rs![when needed] = Me!Calendar Then
            List1.AddItem (rs!Order & " " & _                        rs![sold/ship to])
        End If
        rs.MoveNext
    Loop

This puts in the order number thena space then the clients name. I just need the order number so I can do another seach to pull up all rest of the information.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
Sage020999 earned 50 total points
ID: 2732502
Private Sub List1_Click()

   Dim intPos as integer
   Dim strOrderNo as String

   'Look for the space which seperates the item from the sold/ship to
   intPos  = instr(List1.text," ")
   'If there is not a space, invalid procedure call will occur so if intPos = 0 set the order number to the entire string
   if intpos = 0 then
     strorderno = list1.text
   else
     strOrderNo = left(List1.Text,intpos-1)
    end if
End Sub
0
 
LVL 2

Expert Comment

by:Sage020999
ID: 2732552
Private Sub List1_Click()

   Dim intPos as integer
   Dim strOrderNo as String

   'Look for the space which seperates the item from the sold/ship to
   intPos  = instr(List1.text," ")
   'If there is not a space, invalid procedure call will occur so if intPos = 0 set the order number to the entire string
   if intpos = 0 then
     strorderno = list1.text
   else
     strOrderNo = left(List1.Text,intpos-1)
    end if
End Sub
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2733177
A couple of thoughts here..

1. If you have VB6.. the Split command works very nicely in a parse situation.

  Dim strWork() as String
  strWork() = Split(List1.Text, " ")
  strOrderNo = strWork(0)
  strName = strWork(1)

2. You can make your Database Call MUCH more efficient (even bind it to a control) by using SQL functionality.

<----- Code Begin ----->

  sPath = App.Path & "\clients.mdb"
  Set daoDB36 = DBEngine.OpenDatabase(sPath)

  Dim strSQL as String
  strSQL = "SELECT [When Needed], [sold/ship to] " _
    & "FROM customers " _
    & "WHERE [When Needed] = " _
    & "#" & Format(Me!Calendar, "mm/dd/yyyy") & "#"
  Set rs = daoDB36.OpenRecordset(strSQL)
     
  List1.Clear
  Do Until rs.EOF
    List1.AddItem (rs!Order & " " & rs![sold/ship to])
    rs.MoveNext
  Loop

<----- Code End ----->

0
 

Author Comment

by:doctorlove
ID: 2746060
This worked out the best for me. Thanks!
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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