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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb like combo box

Status
Not open for further replies.

discusmania

IS-IT--Management
Oct 24, 2000
158
AP
guys.....
i have a text box. i have a combo box. what should i do if i want whenever the user enter someting in the text box, it will activate the combo box and goes to the similar text in the combo box list if it is in the list.... 've any idea?

10x,
Ron
 
Code:
'----------------------------------
Sub txtDefectCode_OnKeyDown

	'If cursor down or page down, set focus to cboDefectCauses
	'so that further keypresses are processed there
	'(so further cursor keystrokes will scroll the combo)

	If Window.Event.Keycode = 40 or Window.Event.Keycode = 34 Then
		txtDefectCode.Value = ""
		cboDefectCauses.Focus
	End If

End Sub
'----------------------------------
Sub txtDefectCode_OnKeyUp

	'If Backspace key hit, reset gsSaveKeyedDefectCode to value of text
	'and re-search the combo box

	If Window.Event.Keycode = 8 Then
		gsSaveKeyedDefectCode = txtDefectCode.Value
		If gsSaveKeyedDefectCode <> &quot;&quot; Then
			PositionDefectCausesToKeyedCode
		Else
			'They have &quot;emptied&quot; the text box, so position combo to nothing selected
			cboDefectCauses.SelectedIndex = 0
			cboDefectCauses.SelectedIndex = -1
		End If
	End If

End Sub
'----------------------------------
Sub txtDefectCode_OnKeypress

	Dim sCharacter

	If Window.Event.Keycode = 13 then	'If hit enter, go to combo (if you have found it)
		gbDefectsEntered = True
		gsSaveKeyedDefectCode = &quot;&quot;
		'If selected index <> -1 then found the one they want
		If cboDefectCauses.SelectedIndex = -1 Then
			cboDefectCauses.Focus
		Else
			txtNumDefects.Focus
		End If
		'clear text regardless
		txtDefectCode.Value = &quot;&quot;
	Else
 		sCharacter = Chr(Window.Event.Keycode)
		'Send what has previously been keyed plus this character to the search
		gsSaveKeyedDefectCode = gsSaveKeyedDefectCode & sCharacter
		PositionDefectCausesToKeyedCode
	End If

End Sub
'=======================================================================
Sub PositionDefectCausesToKeyedCode

	Dim nInt

	If cboDefectCauses.SelectedIndex = -1 Then
		cboDefectCauses.SelectedIndex = 0
	End If

	For nInt = 0 to (cboDefectCauses.Options.length - 1)
		'If keyed code > one we're on, bump up the one we're on to the next one
		'and check again
		If nInt <= (cboDefectCauses.Options.length - 1) Then
			If CInt(gsSaveKeyedDefectCode) <= CInt(cboDefectCauses.Options(nInt).Value) Then
				cboDefectCauses.SelectedIndex = nInt
				Exit For
			End If
		Else
			cboDefectCauses.SelectedIndex = (cboDefectCauses.Options.length - 1)
			Exit For
		End If
	Next

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top