What exactly is wrong with this code?
Private Sub VScroll1_Change()
For Each TextBox In frmAdd
Let TextBox.Top = TextBox.Top + -1 * (VScroll1.Value + 10)
Next
End Sub
its saying the top property cannot be read at runtime
Printable View
What exactly is wrong with this code?
Private Sub VScroll1_Change()
For Each TextBox In frmAdd
Let TextBox.Top = TextBox.Top + -1 * (VScroll1.Value + 10)
Next
End Sub
its saying the top property cannot be read at runtime
The code works fine for me. Do you have textboxes on your form for the scrollbar to move them?
do the text boxes have to be named textbox in this code? Sorry ive never tried for each loops before. Thanks matthew, wow a guru helping me ;)
But,
works.Code:Private Sub VScroll1_Change()
Dim aControl As Control
For Each aControl In frmAdd.Controls
If TypeName(aControl) = "TextBox" Then
Let aControl.Top = aControl.Top + -1 * (VScroll1.Value + 10)
End If
Next
End Sub
If there is another way without the test, then let me know Matthew (or anyone).
Regards
Code:'I didn't get it to work either
'but this does
Option Explicit
Public Sub SetTop()
'
'mycontrol = control and increment is increment for forms
'some situtations use more than one form.
'
Dim ctlMyControl As Control
Dim intIncrement As Integer
'
For intIncrement = 0 To Forms.Count - 1
For Each ctlMyControl In Forms(intIncrement).Controls
'
If TypeOf ctlMyControl Is textbox Then
'
ctlMyControl.Top = ctlMyControl.Top + (-1 * (VScroll1.Value + 10))
'
End If
'
Next ctlMyControl
'
Next intIncrement
'
End Sub
Private Sub VScroll1_Change()
Call SetTop
End Sub
i have 2 textboxes and the scrollbar
You have more than 2 text boxes and a vscroll bar on your form. I guarantee it.
Your code is attempting to move EVERY control on the form. I have assumed you declared your variable "TextBox" as a Variant, or that you do not have Option Explicit at the head of your module.
In either case, "TextBox" in your code is merely a variable name like "a" or "b".
In my code and HeSaidJoe's we explicitly check what sort of control we have and then move it.
I hope that explains it to you?
It would have helped you if you had Option Explicit in your module. This would help because you would have recieved an error in your code which would have hinted to you that TextBox needs to be decalred. Then you would have thought about what type of data it will be...
Anyhow enough preaching :)
Cheers
Thanks I understand what I was missing now.