Re: Locking down textboxes.
Quote:
I have 3 frames in an array and only want 2 of the 3 frames textboxes to be locked.
What is the name of the frame and the name of the textboxes which you want to lock?
Re: Locking down textboxes.
the name of the frame is frame, but I have an array of the frame:
frame(0), frame(1), and frame(2)
I want to lock the textboxes in one shot and not have to list them individually.
Re: Locking down textboxes.
I haven't tried this as I don't have access to vb6 here in the office, so I am doing this from memory. please amend if there are any syntax errors
Code:
Sub Lockdown()
For i = 1 To 2 '2 because you want textboxes in 2 frames to be disabled
For Each tb In Frame(i).Controls 'add or subtract from i as required
If TypeOf tb Is TextBox Then
tb.Locked = True
End If
Next
Next
End Sub
Hope this helps..
Re: Locking down textboxes.
koolsid,
Thanks for your reply, but unfortunately it is not working.
There is no .Controls for the frame(i)
Re: Locking down textboxes.
OK, this is what I have and it is working, kindof:
vb Code:
Public Sub Lockdown()
For i = 1 To 2
For Each tb In frame(i).Container
If TypeOf tb Is TextBox Then
tb.Locked = True
tb.BackColor = &H80FF80
End If
Next
Next i
For Each dt In Me.Controls
If TypeOf dt Is DTPicker Then
dt.Enabled = False
End If
Next
End Sub
But the problem is that all of the textboxes backcolor is colored instead of just the 2 frames.
Anyone have any ideas?
Re: Locking down textboxes.
Quote:
But the problem is that all of the textboxes backcolor is colored instead of just the 2 frames.
Is this true for the .locked property as well? what I mean is that all textboxes are getting locked? As per your code only the textboxes in frame(1) and frame(2) should get locked
Re: Locking down textboxes.
I would suggest one further step, and that is the ability to toggle the lock
Code:
Private Sub Lockdown(blnLocked As Boolean)
Dim i As Long
Dim tb As Control
For i = 1 To 2 '2 because you want textboxes in 2 frames to be disabled
For Each tb In Frame(i).Controls 'add or subtract from i as required
If TypeOf tb Is TextBox Then
tb.Locked = blnLocked
End If
Next
Next
End Sub
Private Sub cmdLock_Click()
Lockdown True
End Sub
Private Sub cmdUnLock_Click()
LockDown False
End If
Re: Locking down textboxes.
Hack,
Yes I have both Lockdown and UnLock in my program, but I like your way much better using the boolean.
koolsid,
Quote:
Is this true for the .locked property as well? what I mean is that all textboxes are getting locked? As per your code only the textboxes in frame(1) and frame(2) should get locked
Ok, I have a total of 4 frames. 3 of the frames are in an array; they are named frame.
the 4th frame is named frame1.
The code above locks the textboxes in the 2 frames that I want, but the backcolor of all textboxes is colored and only the 2 frames textboxes should be colored.
Re: Locking down textboxes.
Ok, I just used a quick fix and I cant figure out how to do it otherwise.
I just added "txtLookUp.BackColor = vbWhite" at the end of the sub.
Thanks anyways.
The code looks like this now:
vb Code:
Public Sub Lockdown(blnLocked As Boolean)
For Each tb In frame(0).Container
If TypeOf tb Is TextBox Then
tb.Locked = True
tb.BackColor = &H80FF80
End If
Next
For Each dt In Me.Controls
If TypeOf dt Is DTPicker Then
dt.Enabled = False
End If
Next
txtLookUp.BackColor = vbWhite
End Sub
Re: Locking down textboxes.
You aren't using the boolean variable that you are passing.
Re: Locking down textboxes.
Hack wrote:
Quote:
You aren't using the boolean variable that you are passing.
Not sure what you mean Hack.
This is what I have with your code:
vb Code:
Public Sub Lockdown(blnLocked As Boolean)
For Each tb In frame(0).Container
If TypeOf tb Is TextBox Then
tb.Locked = True
tb.BackColor = &H80FF80
End If
Next
For Each dt In Me.Controls
If TypeOf dt Is DTPicker Then
dt.Enabled = False
End If
Next
txtLookUp.BackColor = vbWhite
End Sub
and this in the other subs:
vb Code:
Public Sub Locked()
Lockdown True
End Sub
Public Sub UnlockTB()
Lockdown False
End Sub
OK, now I have this and it seems to work fine:
vb Code:
Public Sub Lockdown(blnLocked As Boolean)
If blnLocked = True Then
For Each tb In frame(0).Container
If TypeOf tb Is TextBox Then
tb.Locked = True
tb.BackColor = &H80FF80
End If
Next
For Each dt In Me.Controls
If TypeOf dt Is DTPicker Then
dt.Enabled = False
End If
Next
txtLookUp.BackColor = vbWhite
Else
For Each tb In frame(0).Container
If TypeOf tb Is TextBox Then
tb.Locked = False
tb.BackColor = vbWhite
End If
Next
For Each dt In Me.Controls
If TypeOf dt Is DTPicker Then
dt.Enabled = True
End If
Next
End If
End Sub