Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read Listbox Contents to string

Status
Not open for further replies.

h3lm3t

Technical User
May 27, 2003
16
0
0
GB
Hi there, i need help in putting a listbox selection into a string. Ive tryed it may ways, and keep getting, "invalid use of null"

i have 4 global variables

2 listboxes with 2 columns each, each listbox is bound to column 1, and only lists column 2, using the 0",1" trick.

heres my code, inside of the button click event:

dim catChoice as integer
dim manuChoice as integer

dim catString as string
dim manuString as string

----------cmdGetChoice_Click event-----------

If Me.lstManuPicker.Value = 0 Then ' deal with no choices

MsgBox "Please Choose a Manufacturer", vbOKOnly, "Form Error"

ElseIf Me.lstCatPicker.Value = 0 Then

MsgBox "Please Choose a Stock Category", vbOKOnly, "Form Error"

Else

manuChoice = Me.lstManuPicker.Value ' get manufacturer integer choice
catChoice = Me.lstCatPicker.Value ' get category integer choice

manuString = Me.lstManuPicker.Column(2, manuChoice) ' get manufacturer text from list box
catString = Me.lstCatPicker.Column(2, catChoice) ' get category text from list box

[Forms]![frmStock]![txtManuName]![Text] = manuString ' put text into target from
[Forms]![frmStock]![txtStockCatName]![Text] = catString ' put text into target from

End If
----------------

any ideas ??
i would just bind the strings to column 2 of the listboxes, but i need the bound column data elsewhere.

Thanx for any and all help

regards
h3lm3t
 
Hi h3lm3t,

Try this:

If Me!lstManuPicker = 0 Then ' deal with no choices
MsgBox "Please Choose a Manufacturer", vbOKOnly, "Form Error"
ElseIf Me!lstCatPicker = 0 Then
MsgBox "Please Choose a Stock Category", vbOKOnly, "Form Error"
Else
manuChoice = Me!lstManuPicker ' get manufacturer integer choice
catChoice = Me!lstCatPicker ' get category integer choice
manuString = Me!lstManuPicker.Column(2) ' get manufacturer text from list box
catString = Me!lstCatPicker.Column(2) ' get category text from list box

Forms!frmStock!txtManuName = manuString ' put text into target from
Forms!frmStock!txtStockCatName = catString ' put text into target from
End If

Your using VB syntax, Access uses VBA, there are subtle differences between them.

Bill
 
Hi Bill that worked a treat Sir, thank you!!
Wonder what other problems await me :cool:

cheers for the help
h3lm3t
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top