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

contents of txt box into combo box *as* the user types them 1

Status
Not open for further replies.

david2001

Technical User
Oct 2, 2001
24
0
0
GB
Hello,

I need to have what ever the user is typing in "txtbox1" automaticly be entered into cboBox1, *AS* the user types it letter by letter but with out changing the record source and so on of the combo box. They are both on frmForm1.

I know that this may not be the best way of doing things but there are very good reasons why I have to do this (unfortunatly).

Can some one suggest how I may do this as I have spent the last 2 days working on just this one small problem.

Thank you for your time,

david2001
 
Oh,

and will there be spaces in the text entered in this box ?

J
 
Add code to the KeyPress event for txtbox1. The code will append characters to the contents of cboBox1 as you type. The code catches backspaces and removes a character from the cboBox1. And it catches and ignores control characters.

Private Sub txtbox1_KeyPress(KeyAscii As Integer)

Dim strCharacter As String
If KeyAscii = 8 Then
cboBox1 = Left(cboBox1, (Len(cboBox1) - 1))
Else
If KeyAscii < 32 Or KeyAscii > 126 Then
Exit Sub
Else
strCharacter = chr(KeyAscii)
cboBox1 = cboBox1 & strCharacter
End If
End If

End Sub
 
Hi everyone.

Thank you for your replys, i appreciate them,

To janeC:

txtbox1 is unbound and Yes, there will be spaces and maybe numbers as well.

To sbohman:

Thanks for the code, I used it exactly as you suggested but it did not work. As soon as you perform a keypress in txtbox1 (and even before the letter you typed was shown) Access gives the following error in a debug box:
Run-time error '-2147352567 (80020009)':

The following line of code is then highlighted in yellow:

TrackTitle = TrackTitle & strCharacter

Any further suggestions please.


Thanks again

david2001
 
My test form only has the two object, names exactly as shown in the code. It works properly in mine.

Does the error message give any other description besides the numbers?
 
Hi sbohman,

Thanks for your reply.

Nope in the error message it only gave the numbers but just in case it matters, I am using Access 2000 and limit to list is set to yes for the combo box.

Regards,

david
 
Hi fellow forum members,

I still need help with this problem if anyone can suggest anything - its really driving me mad. Such a hard thing to do for such a simple task.

Kind regards,

david
 
David,

sbohman's code works fine for me too. Check the RowSource for your combo box. For example, if the field its set to is a number type and you enter non-numeric data in your text box, you will get that error.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top