June 24, 2005 at 5:09 am
Hi
I have a form with many fields on it. 12 of these fields (named Unit1 through to Unit12) need to be unlocked according to a given number unique to each record. All field start as locked
If the number appearing in the record is 5, then 1 - 5 need to be unlocked, 6 - 12 need to remain locked.
I've done this before using a For Next loop, but am struggling to make it work this time.
I have something like the following in the OnCurrent event of the form:
Dim Un As Variant (sometimes there are nulls)
Dim i As Integer
Dim Fn As Field
Un = DLookup("[units]", "Myquery") 'the given number - which is different for each record
If Un > 0 Then
For i = 1 To Un
Fn = "unit" & i 'this will show Unit?(fieldname)
Fn.locked = False
Next i
else
exit sub
end if
If you can suggest the correct way to do this I would be grateful.
Paul
June 24, 2005 at 6:03 am
I don't think you can do it that way.
I think I would create a function with the parameters index and number and the function would return true of false depending on if the record needs to be locked or not... then call field1.locked = fnLock (1, 5)
June 24, 2005 at 2:24 pm
yor problem is syntax:
try:
For i = 1 To 12
Me.Controls("unit" & i).locked = (Un <= i)
Next i
* Noel
June 24, 2005 at 8:52 pm
so much simpler .
June 28, 2005 at 4:20 am
Absolutely brilliant!
Thanks very much for this. It's exactly what I want.
Sorry for late reply - I've only just had the chance to get back to this.
Many thanks again
Paul
June 28, 2005 at 9:20 am
As long as it's fixed now... Happy to almost help .
June 28, 2005 at 12:52 pm
me too
* Noel
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply