For each next loop

arage

Registered User.
Local time
Today, 16:50
Joined
Dec 30, 2000
Messages
537
For each next loop
I typed the following but get the error that “Object doesn’t support this property or method” for statements in my FOR loop. The below is specified in my frmDataEntry’s onCurrent event and ctl was defined as a variable of control type. Please advise.

For Each ctl In [Forms]![frmDataEntry]
ctl.Locked = True
ctl.Enabled = False
Next ctl
 
Try this

For Each ctl In Me.Controls
ctl.Locked = True
ctl.Enabled = False
Next ctl
 
Thanks Robert but that didn’t work for me as it told me that ctl didn’t support that object or property so I came up with below, problem is I have more than one tab control and more than one type of control on that tab.

If IsNull(Me.DateSentToAccounting) = False Or IsNull(Me.DateSentToJon) = False Then
For Each ctl In Me.tabPromotionPreApproval.Controls
If ctl.ControlType = acTextBox Then
ctl.Locked = True
ctl.Enabled = False
End If
Next ctl
 
what do we mean by acTextBox in terms of concept & how does access know I’m referring to an active text box, what if don’t want an active text box what if I want an active combo box or active frame or active radio button what term do I use then? Or how do I find out in help what they are called?
 
Hi arage

I have had a similar problem when referencing controls. Basically what I was trying to do was to create an undo routine and restore the old values by using the code:
ctl.Value = ctl.OldValue. The problem I had was trying to reference each control type i.e acTextBox, acComboBox etc. The code worked fine for restoring old values to each text box but it wouldn't do it for the combo boxes and no error message was being thrown up. In the end because I only had a few controls on my form I referenced each one individually and finally got it to work.

It's shame that a control doesn't have an Index property like in VB where it gives you the opportunity to create a control array. A much nicer facility to code with. Thinking about it you probably could make use of the tag property and then use a Select Case statement that references this in your For..Next loop.. or something along those lines.

If you need the list of the different control type constants have a look at Access VB help under ControlType property and there you'll find a full list.

HTH
Rob
 
the concept is known as an intrinsic constant.
 
Thanks, but I got to it using this way:

'lock record if submitted...
If IsNull(Me.DateSentToAccounting) = False Or IsNull(Me.DateSentToJon) = False Then
For Each ctl In Me.Controls
If ctl.ControlType <> acTabCtl Then
If ctl.ControlType <> acPage Then
If ctl.ControlType <> acLabel Then
If ctl.ControlType <> acCommandButton Then
ctl.Locked = True
ctl.Enabled = False
End If
End If
End If
End If
Next ctl
End If

The above will lock the controls on the form nicely (basically all of them) but when I try to unlock I’m finding that I’m unlocking all of them rather then just the ones I want to. So I thought I’d try to use the TABINDEX property to do so. But how could I do so with a SELECT statement?

I tried, but ofcourse am wrong:

Select Case Me.Controls.Index
Case "4" Or "5" Or "0" Or "1" Or "2" Or "11" Or "12" Or "14" Or "15" Or "16" Or "17" Or "13" Or "6" Or "7" Or "16" Or "17" Or "18" Or "19" Or "20" Or "5" Or "0" Or "1" Or "2" Or "3" Or "4" Or "6" Or "7"
ctl = Me.Controls
ctl.Locked = False
ctl.Enabled = True
End Select
 

Users who are viewing this thread

Back
Top Bottom