How can I avoid the change event firing if the change to the textbox is made programatically i.e. automatic. I only want the event to fire if the change is made by the user typing the changes.
Dim ProgChange As Boolean
Private Sub ChangeText(Where As TextBox, What As String)
ProgChange = True
Where.Text = What
ProgChange = False
End Sub
Private Sub Command1_Click()
ChangeText Text1, "hello"
End Sub
Private Sub Form_Load()
ProgChange = False
End Sub
Private Sub Text1_Change()
If Not ProgChange Then
MsgBox Text1.Text
End If
End Sub
----------------------------------------------------------- Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
Thanks Sunaj, however, I am not too clear on what you mean.
Here is a bit more on what I am trying to do....
When a user selects a row in a spreadsheet control I am using three text boxes are populated with data. If the user changes one of these values the spreadsheet is disabled until a button is clicked and the changes wrote back to the spreadsheet. However, if the user selects a subsequent row then the change event fires and locks the spreadsheet....this becomes a problem if the user has selected the wrong row and can only free it up if the button is clicked which has an impact further down the line when writing to my database as it generates unnecessary transactions.
Hope this gives you a better idea of what I require.
I'm afraid I don't understand. The change event that disables the spreadsheet is of the textbox, right?
So why does the spreadsheet lock if the user select a new row? That should not fire the change event of the textbox. Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
ahh of course. Then my solutio should work.
The idea is to set a public bbolean that determines if teh code in the change event should be executed or not; If the user change it -> its executed, but if it is change by code the boolean is set to true and the code is not executed.
So in your case i guess you got some code in the spreadsheet change event that updates the textboxes -right?
Set the boolean to true before this update and to false again after. And make sure that the the value of the boolean is checked before the code in the textbox_change event is executet - do you see? Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
I agree with sunja, setting up your own function to test if the textboxes will change or not is the way to go. That way you can avoid doing it in the keypress like perplexd said, although that could work too, just have to write all the code over again. Hope you get it figured out. ----------------
Joe
Did you use the exact code I showed about? If not, post your code, your declarations and indicate where you get the error. (and read faq222-2244) Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
Private Sub DisableSpread(X As TextBox, Txt As String)
Disable = True
X.Text = Txt
Disable = False
End Sub
Private Sub sprBOMDets_Click(ByVal Col As Long, ByVal Row As Long)
If Col = 0 Then
For i = 1 To 4
sprBOMDets.Col = Col + i
sprBOMDets.Row = Row
If i = 1 Then DisableSpread txtComponent, sprBOMDets.Text
ElseIf i = 2 Then
DisableSpread txtQty_Use, sprBOMDets.Text
ElseIf i = 3 Then
DisableSpread txtUM, sprBOMDets.Text
ElseIf i = 4 Then
DisableSpread txtNotes, sprBOMDets.Text
End If
Next i
End If
Please see my code below (missed some off before...sorry);
Dim Disable As Boolean
Private Sub DisableSpread(X As TextBox, Txt As String)
Disable = True
X.Text = Txt
Disable = False
End Sub
Private Sub sprBOMDets_Click(ByVal Col As Long, ByVal Row As Long)
If Col = 0 Then
For i = 1 To 4
sprBOMDets.Col = Col + i
sprBOMDets.Row = Row
If i = 1 Then DisableSpread txtComponent, sprBOMDets.Text
ElseIf i = 2 Then
DisableSpread txtQty_Use, sprBOMDets.Text
ElseIf i = 3 Then
DisableSpread txtUM, sprBOMDets.Text
ElseIf i = 4 Then
DisableSpread txtNotes, sprBOMDets.Text
End If
Next i
End If
End Sub
Private Sub txtComponent_Change()
If Not Disable Then
If UCase(lblBOMStatus.Caption) Like "AMEND*" Then
sprBOMDets.Enabled = False
Dets_Change = True
End If
End If
End Sub
The run time error occurs at the point highlighted in Red. Many thanks for all your help.
sprBOMDets.text represents the text contents of a cell within my grid control, and it is this value that I want to pass to the text property of the text box X.
Is there something very simple that I am missing here?
I have tried using your code sample from your first post and this works without any problems. However, as soon as I replace Text1 in this line, ChangeText Text1, "hello" with txtComponent (the name of my text box, I receive the run time error (13 type mismatch).
That does sound a little strange.. If it work with text1 and not with txtcomponent, there but be something different (other than the name.).
For startes you could place a new textbox on the form, check that is works and then rename it to 'txtcomponent'. If you have other changes do them one step at a time to find out where the problem lies.
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.