Hi,
I am trying to set up some code which will use a listbox (multiselect) to populate a textbox. A second bit of code runs when the userform opens, checks the contents of the textbox to see what has been previously entered, and sets the .selected property on the listbox entries to match. This is the part causing me problems.
I have the following set up in Word 2000:
- A textbox named txtElectricalSystem which I have placed in the document.
- A userform with a listbox (multiselect) called ElectricalSystem
What I want to do is check each of the items in the listbox valuelist to see wether the text of that ElectricalSystem listbox item is contained within the text of the txtElectricalSystem textbox.
My code is this:
This doesn't work - even when the text in the ElectricalSystem listbox category matches the text in the txtElectricalSystem, INSTR returns 0.
I have tried all sorts with this - changing the vbcompare setting, using two string variables to hold the contentds of the listbox and textbox... I have checked the LEN of the two strings and they match exactly.
Can anybody spot what is wrong with the INSTR instruction?
Thanks for any help.
I am trying to set up some code which will use a listbox (multiselect) to populate a textbox. A second bit of code runs when the userform opens, checks the contents of the textbox to see what has been previously entered, and sets the .selected property on the listbox entries to match. This is the part causing me problems.
I have the following set up in Word 2000:
- A textbox named txtElectricalSystem which I have placed in the document.
- A userform with a listbox (multiselect) called ElectricalSystem
What I want to do is check each of the items in the listbox valuelist to see wether the text of that ElectricalSystem listbox item is contained within the text of the txtElectricalSystem textbox.
My code is this:
Code:
For i = 0 To ElectricalSystem.ListCount - 1
If InStr(0, ElectricalSystem.List(i, 0), txtElectricalSystem, vbTextCompare) > 0 Then
End If
MsgBox (InStr(1, ElectricalSystem, ThisDocument.txtElectricalSystem.Value))
Next i
This doesn't work - even when the text in the ElectricalSystem listbox category matches the text in the txtElectricalSystem, INSTR returns 0.
I have tried all sorts with this - changing the vbcompare setting, using two string variables to hold the contentds of the listbox and textbox... I have checked the LEN of the two strings and they match exactly.
Can anybody spot what is wrong with the INSTR instruction?
Thanks for any help.