textbox dont clear with Text1.Text=""

Hi,

I have a problem with clearing the textbox using command text1.text = "". Somehow after the vbKeyReturn is sent, the textbox won't clear completely and always shows text "13" on the textbox (i wonder why... ). Is there a bug to this or i am missing something else? How can i clear the textbox completely for the next entry?

Following is the code snippet:

Private Sub Text1_Change()
If Text1.SelStart >= Text1.MaxLength Then
SendKeys vbKeyReturn

SQL = "select ID, NAME from student where ID like '" & Text1.Text & "'"
adcStudent.RecordSource = SQL
adcStudent.CommandType = adCmdText
adcStudent.Refresh
Set hfgStudent.DataSource = adcStudent

Text1.Text = ""
Text1.SetFocus

End If
End Sub

Thanks in advance for any information or guide!

Cheers,
Leynie
[954 byte] By [leynie] at [2007-11-19 14:07:57]
# 1 Re: textbox dont clear with Text1.Text=""
Change:
SendKeys vbKeyReturn

To:
SendKeys {"ENTER"}

The reason it shows 13 in the textbox was that
vbKeyReturn's constant value is 13

Hope it helps!:wave:
HanneSThEGreaT at 2007-11-9 20:28:51 >
# 2 Re: textbox dont clear with Text1.Text=""
Great !

Absolutely Right !
rahul.kul at 2007-11-9 20:29:51 >
# 3 Re: textbox dont clear with Text1.Text=""
Oh you are right!! It clears the textbox correctly now using
SendKeys "{ENTER}"

Thanks alot!!! :)

cheers,
Leynie
leynie at 2007-11-9 20:30:50 >
# 4 Re: textbox dont clear with Text1.Text=""
Private Sub Text1_Change()
If Text1.SelStart >= Text1.MaxLength Then
SendKeys vbKeyReturn
SQL = "select ID, NAME from student where ID like '" & Text1.Text & "'"
adcStudent.RecordSource = SQL
adcStudent.CommandType = adCmdText
adcStudent.Refresh
Set hfgStudent.DataSource = adcStudent

Text1.Text = ""
Text1.SetFocus
End If
End Sub
[/code]

I have a question: What I do not understand in that code is: This all is done in Text1_Change() and when the limit of text is reached then it leaves the textbox1 because of enter command then you clear the box and set the focus back to Text1 Field.
Question is why you do ENTER respectively why you want to leave the Text1 field. ? Is there any specific code in text1.LostFocus or is it only for getting a BEEP, because then you also can use 'Beep' instead of SendKeys "{ENTER}"

Jonny Poet :wave:
JonnyPoet at 2007-11-9 20:31:49 >
# 5 Re: textbox dont clear with Text1.Text=""
Hi,

Actually my intention is to associate the textbox with a scanner that once the text or code is scanned it will automatically linked to the database and display the matching records... So i was thinking to send Enter key to trigger the event (without using the keyboard)... Now it works as intended just that the limitation will be the text which is limited to certain length... Hmm or maybe it can be better if once there is text in the textbox then it will automatically match the text with record in the database and display them on the grid.... :)

Does it make sense? Or am i making it more difficult? :)

cheers,
leynie
leynie at 2007-11-9 20:32:59 >
# 6 Re: textbox dont clear with Text1.Text=""
Hi,

Actually my intention is to associate the textbox with a scanner that once the text or code is scanned it will automatically linked to the database and display the matching records... So i was thinking to send Enter key to trigger the event (without using the keyboard)... Now it works as intended just that the limitation will be the text which is limited to certain length... Hmm or maybe it can be better if once there is text in the textbox then it will automatically match the text with record in the database and display them on the grid.... :)
What sort of scanner is that. Does it read line by line out of a document so it needs to be triggered ? or Is this a hand-scanner as used in supermarkets reading an ID and showing the product ? Are all the inputs in the same length so you can limit the length of the input ? Because in the moment that thing is triggered in reaching MaxLength and in my understanding the SendKeys does really nothing which is useful in your case.

...Hmm or maybe it can be better if once there is text in the textbox...As you know the _Change() Function checks every sign you put in. So you need some limitation which finishes your inputs
and then comparing with database. Otherwise the select Statement will give lots of unexpected results and it will work with every latter you put in like you are searching for ID 125 it will give a databasequery for
1 ....
12...
125...
and so on
I dont know whats scanned but for example if the text itself is limited you can look for specific signswhich terminates the strings and that way triggering the textbox to compare and show.

For example if the scanned stream is "125 346 457" then you can look for the spaces. So tell a bit more about the scanner and what it scans, how this data looks like.

Jonny Poet
JonnyPoet at 2007-11-9 20:33:52 >
# 7 Re: textbox dont clear with Text1.Text=""
Hi,

Hmm, it's a CCD hand-scanner similar to those used in supermarket for scanning product and displaying the information etc. I am planning to scan the userID instead which will be input into the textbox (Text1.Text)... The userID would be in different length though... some will have length 4, some length 6, and some 8... The code that i tried previously is tested only with one type of length (so there is a limitation there)...

The ultimate plan is to scan the userID (which will be input into the textbox), then send "ENTER" key (no keyboard will be used) to trigger the event to match the ID with the database and display the matching records on flexgrid and maybe some update, or add to the database... The ID will be in the form of like continuos string without spacing for eg: AB1234.

Thanks again for any guide and information!

cheers,
leynie
leynie at 2007-11-9 20:34:56 >
# 8 Re: textbox dont clear with Text1.Text=""
... it's a CCD hand-scanner similar to those used in supermarket for scanning product and displaying the information etc. Ithought so :)
...The ultimate plan is to scan the userID (which will be input into the textbox), then send "ENTER" key.. Yea I see, but who will send the ENTERKEY ? :p hmmmm ? :eek: I'm frightened NOOOBODDDY ! Because IMHO the scanner doesn't and your program only does when maxnumbers are reached.
So as I was frightened your SendKeys "{ENTER}" is a useless command, it is not your Trigger Your Trigger in the moment is length of ID input
The needed idea is how can I change all iD's to the needed length so they have all a size of maxlength. To get the beep for knowing its scanned you still can use your sendkeys or you simple use 'Beep' Command instead of SendKeys "{ENTER}" Command.
An Idea would be, If you get in the first sign in your Box then start a timer and read out the full string 100 msecs later ( could be also 200 if 100 is to quick ) You have to test what works

Option explicit
Private bIsStarted as Boolean

Private Sub Text1_Change()
if bIsStarted = False then
bisStarted = True
MyTimer.Enabled = True ' In the properties set it to False and Time as 100 or 200
end if
end Sub

'And the Rest of your Code ( havn't checked if it is OK)

Private Sub MyTimerTimer()
' Because time is delayed now, Text1.Text is full now I hope
SQL = "select ID, NAME from student where ID like '" & Text1.Text & "'"
adcStudent.RecordSource = SQL
adcStudent.CommandType = adCmdText
adcStudent.Refresh
Set hfgStudent.DataSource = adcStudent

Text1.Text = ""
'Text1.SetFocus Should not be necessary because it is still there
Beep ' You here a Beep
bIsStarted = False
MyTimer.Enbaled = False
End Sub

I hope that helps :wave:

Jonny Poet
JonnyPoet at 2007-11-9 20:35:53 >