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

change event with Multiline textbox 1

Status
Not open for further replies.

MikeCt

Programmer
Nov 6, 2001
44
US
Hi
I have 3 textboxes on my form named tbox1,tbox2 and tbox3.
tbox1 and tbox2 have the multiline property set to false.
tbox3 has the multiline property set to true.

I tab down thru the textboxes not changing anything in the textboxes. I'm able to tab thru tbox1 & tbox2 without triggering the change event, but when I tab into tbox3 the change event is triggered.

I cleared the textboxes using tbox1 = "" tbox2 = ""
tbox3 = "" before tabing thru them

When I check the value of tbox3 at runtime the value is
chr(13) & chr(13) ( " 2 square boxes " )

I tried clearing tbox3 using tbox3 = chr(13) & chr(13) instead of tbox3 = "" but the change event was still triggered.

Is there a way to clear tbox3 that will stop it from having the change event triggered when I tab thru it or is there a way to deal with this action.

Thanks
Mike



 
I cannot replicate your problem in any way - neither the change event nor the runtime value of tbox3.

This must be becasue I am simplifying the code too much. I think we need to see your exact code in order to be able to diagnose the problem.
 
Me neither using this simple test, which I bet is the same or very close to strongm's attempt at reproducing your problem...
[tt]
Option Explicit

Private Sub Text1_Change()
Debug.Print "Text1_Change"
End Sub

Private Sub Text2_Change()
Debug.Print "Text2_Change"
End Sub

Private Sub Text3_Change()
Debug.Print "Text3_Change"
End Sub
[/tt]


Good Luck

 



Check out TabKeyBehavior. If TRUE, change to FALSE.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip, in VB6.0 we don't have a tabkeybehavior property??? Are you perhaps thinking of VB.NET???
 
Skip, VB6 does not have a TabKeyBehaviour property for any of it's default controls. Perhaps you mean the TabStop property - but changing that to FALSE would simply prevent the OP from tabbing through the text boxes - which would simply be hiding the problem, not fixing it.
 
Thank you for your help

I tried to create a simple form that produces the same problem. I'm not sure how to attach a table to this if
needed. I'm using access if that is important. If I need
to switch to a different forum please advise
Mike


Option Explicit
Dim rsRs1 As Recordset 'Original recordset for data
Dim gstrSQL1 As String

Private Sub Form_Load()
Screen.MousePointer = vbHourglass

gstrSQL1 = "SELECT * From Consignors ORDER BY [Last Name],[First Name];"
Set rsRs1 = gSequelDB.OpenRecordset(gstrSQL1, dbOpenSnapshot)
rsRs1.MoveFirst
Call DisplayFields
Screen.MousePointer = vbDefault
End Sub

Private Sub DisplayFields()
Dim varHold As Variant
varHold = rsRs1("First Name")
If IsNull(varHold) Or Trim(varHold) = "" Then varHold = ""
tbox1 = varHold

varHold = rsRs1("Last Name")
If IsNull(varHold) Or Trim(varHold) = "" Then varHold = ""
tbox2 = varHold

varHold = rsRs1("Notes")
If IsNull(varHold) Or Trim(varHold) = "" Then varHold = ""
tbox3 = varHold
End Sub



Private Sub tbox1_GotFocus()
tbox1.BackColor = LightBrown
End Sub
Private Sub tbox1_LostFocus()
tbox1.BackColor = vbWhite
End Sub
Private Sub tbox1_Change()
If Trim(tbox1) <> "" Then
If Len(Trim(tbox1)) = 1 Then
tbox1 = StrConv(Trim(tbox1), vbUpperCase)
tbox1.SelStart = 2
End If
End If
End Sub
Private Sub tbox1_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc(vbCrLf) Then tbox2.SetFocus
End Sub


Private Sub tbox2_GotFocus()
tbox2.BackColor = LightBrown
End Sub
Private Sub tbox2_LostFocus()
tbox2.BackColor = vbWhite
End Sub
Private Sub tbox2_Change()
If Trim(tbox2) <> "" Then
If Len(Trim(tbox2)) = 1 Then
tbox2 = StrConv(Trim(tbox2), vbUpperCase)
tbox2.SelStart = 2
End If
End If
End Sub
Private Sub tbox2_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc(vbCrLf) Then tbox3.SetFocus
End Sub


Private Sub tbox3_GotFocus()
tbox3.BackColor = LightBrown
End Sub
Private Sub tbox3_LostFocus()
tbox3.BackColor = vbWhite
End Sub
Private Sub tbox3_Change()
If Trim(tbox3) <> "" Then
If Len(Trim(tbox3)) = 1 Then
tbox3 = StrConv(Trim(tbox3), vbUpperCase)
tbox3.SelStart = 2
End If
End If
End Sub
Private Sub tbox3_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc(vbCrLf) Then tbox1.SetFocus
End Sub
 
If you check out the TabIndex property of the controls on your form you could leave all the tabbing to Windows and it would go from box 1 to 2 to 3 to 1 when the user presses Tab automatically.

Just set the TabIndex of box 1 to 0, box 2 to 1 and box 3 to 2 and remove your code from all the KeyPress events.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Andy, I think you'll find that the Tab key is already doing exactly what it is supposed to do. The code you are referring to makes the Return key work like Tab (mind you, that KeyPress code is slightly wrong ... but in a way that happens to make it work ...)
 

(1) If I remove the sendkeys procedures, the change event is not triggered as I tab thru tbox3.
(2) Problem is my customer has asked that I use the enter key for tabbing thru the textboxes
(3) The customer is running Windows 7 which does not work with If KeyAscii = Asc(vbCrLf) Then SendKeys "{Tab}"
See question Feb 19 "Sendkeys with windows 7"

Thanks again
Mike
 
>If I remove the sendkeys procedures

What SendKeys procedures? You have not shown those in your code.

And can we confirm, as it now looks, that you are not tabbing through the textboxes, you are in fact using the Enter key made to work (a bit) like the tab key?

Because that would do it ...

Multiline textboxes accept carriage returns as input, whilst singleline textboxes ignore them. This in turn causes a change event.

So this'll do the trick (not that it's good code) ...

Private Sub tbox3_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc(vbCrLf) Then
tbox1.SetFocus
KeyAScii=0
End If
End Sub
 
Sorry I meant KetPress procedures
Thank you for the explaination and the workaround
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top