Form uneditable except for one control (1 Viewer)

pr2-eugin

Super Moderator
Local time
Today, 21:15
Joined
Nov 30, 2011
Messages
8,494
This setup is for Employee attendance system. I have a continuous form setup with header, footer and details section.

Header contains one ComboBox which populates all the dates in the hoursLog table; and is used to filter the form.

Details section is based from a Query linked to the table. So edits are allowed and this reflects in the table.

Footer section contains the Sum() fields in the details section.

All works fine. The user opens the Form, default to today's date, so the hours can be updated as required. However, when the user uses the ComboBox to travel back in time. I want to render the fields uneditable. So I used a check in the FormCurrent if the ComboBox value <> Date() Then Me.AllowEdits = False. This is great, except the comboBox (unbounded) is also becoming uneditable, so I cannot go back to my original date (or) any other date for that matter.

Yes I can close and reopen the form, but this will be a pain, if the user only wants to check, if the hours have been entered right on different dates. If they need to check this, they have to close and come back several times.

The option I have is to loop through the controls and go around, but I feel there should be something very basic that I am missing. Just make the fields in the details section locked? Something of that sort? Suggestions, ideas are welcome.
 

vbaInet

AWF VIP
Local time
Today, 21:15
Joined
Jan 22, 2010
Messages
26,374
You're not missing anything Paul. AllowEdits will block all controls, so you would have to cycle through each control within the Details.

Or you could use Conditional Formatting.
 

pr2-eugin

Super Moderator
Local time
Today, 21:15
Joined
Nov 30, 2011
Messages
8,494
so you would have to cycle through each control within the Details.
Thanks vbaInet, I was trying to avoid this, but if it has to be done I might as well do it.
Or you could use Conditional Formatting.
Using Conditional Formatting I can only Enable or Disable, I cannot lock the fields from edit can I?
 

vbaInet

AWF VIP
Local time
Today, 21:15
Joined
Jan 22, 2010
Messages
26,374
Yeah, just Enable/Disable.

I just tried to see if a nested combo box in a subform would do it but no it didn't.
 

pr2-eugin

Super Moderator
Local time
Today, 21:15
Joined
Nov 30, 2011
Messages
8,494
Well I am going with the Details control lock. It seems to sort what I want, just did not want to resort to that if there was something simple to do. But hey-ho-hey-ho For Loop here we go. ;) Thank you !
 

vbaInet

AWF VIP
Local time
Today, 21:15
Joined
Jan 22, 2010
Messages
26,374
It will be a tad quicker if you save the control references in a Collection/Dictionary when the form loads and do a For Each on the collection of references in the Collection/Dictionary.

You only save the references of the relevant controls. This way you don't have to cycle through all the irrelevant controls.

This is how I do it.
 

pr2-eugin

Super Moderator
Local time
Today, 21:15
Joined
Nov 30, 2011
Messages
8,494
It will be a tad quicker if you save the control references in a Collection/Dictionary when the form loads and do a For Each on the collection of references in the Collection/Dictionary.
Sounds like a very interesting solution, although hardcoding values would be a bit tacky? If I add new controls in future this should be added to the collection. Of course is lot better than looping through all controls. In this design however it is only 7 text boxes and I need them all to be locked. :D
 

vbaInet

AWF VIP
Local time
Today, 21:15
Joined
Jan 22, 2010
Messages
26,374
Remember a control is an object, so I mean the object reference. I can give you an example if you want.

7 controls is nothing then :D
 

pr2-eugin

Super Moderator
Local time
Today, 21:15
Joined
Nov 30, 2011
Messages
8,494
Ha Ha ! Continuous form too (just adding that). I would be glad to look at an example please.
 

vbaInet

AWF VIP
Local time
Today, 21:15
Joined
Jan 22, 2010
Messages
26,374
I'll make one up. Something like this:
Code:
dim dctCtl as dictionary
dim ctl as access.control

set dctCtl = new dictionary

' to add to dictionary
for each ctl in me.detail.controls
    if ... some condition ... then
        dctCtl.add ctl
    end if
next


' to use
for each ctl in dctCtl.Keys
    ctl.locked = true/false
next
 

pr2-eugin

Super Moderator
Local time
Today, 21:15
Joined
Nov 30, 2011
Messages
8,494
Cheerio vbaInet. I will play with that now :D
 

Users who are viewing this thread

Top Bottom