doctorlove
asked on
getting just a certain part from a listbox
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.
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.
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
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
ASKER
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(sPat h)
Set rs = daoDB36.OpenRecordset("cus tomers")
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.
Here's my code right now:
sPath = App.Path & "\clients.mdb"
Set daoDB36 = DBEngine.OpenDatabase(sPat
Set rs = daoDB36.OpenRecordset("cus
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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(sPat h)
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(strS QL)
List1.Clear
Do Until rs.EOF
List1.AddItem (rs!Order & " " & rs![sold/ship to])
rs.MoveNext
Loop
<----- Code End ----->
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(sPat
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(strS
List1.Clear
Do Until rs.EOF
List1.AddItem (rs!Order & " " & rs![sold/ship to])
rs.MoveNext
Loop
<----- Code End ----->
ASKER
This worked out the best for me. Thanks!