TonyMannella
asked on
MS Access lock editing of a form and its subfroms based on a certain date or a date in the manin form
Hi,
I have constructed an employee time and expense form. What I would like to do is to disable the user from going back to change the values in a form and its subforms (subform Time, and subform expense). The main form has a "Week Ending" text box. I would like to disable editing after 2 days past on the week ending combo box on the main form as well as both subforms. Can this be done. See attached screenshot
time-Expenseforms.jpg
I have constructed an employee time and expense form. What I would like to do is to disable the user from going back to change the values in a form and its subforms (subform Time, and subform expense). The main form has a "Week Ending" text box. I would like to disable editing after 2 days past on the week ending combo box on the main form as well as both subforms. Can this be done. See attached screenshot
time-Expenseforms.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Quick Question, How would I put a message box in there to alert the user they can no longer add their time and expense. Where would I put that code in your code?
ASKER
Still working on this and will let you know the results
Hi - I'm sorry I missed your last comment.
If DateAdd("d", 2, Me.WeekEnding) <= Date then
me.AllowEdits = False
Me.[subform Time].Locked = true
Me.[subform expense].Locked = true
'*** Add your message box here:
msgBox "Edits have been disabled"
Else
me.AllowEdits = true
Me.[subform Time].Locked = False
Me.[subform expense].Locked = false
end if
Also, if the code is in the Current Event as I suggested, it will fire when the form opens and also as the user navigates through records (it fires following a record change, once the user is on the record).
If you want this code to fire when the user enters data, you should also add the code to the After UPdate event of your form or the control.
If DateAdd("d", 2, Me.WeekEnding) <= Date then
me.AllowEdits = False
Me.[subform Time].Locked = true
Me.[subform expense].Locked = true
'*** Add your message box here:
msgBox "Edits have been disabled"
Else
me.AllowEdits = true
Me.[subform Time].Locked = False
Me.[subform expense].Locked = false
end if
Also, if the code is in the Current Event as I suggested, it will fire when the form opens and also as the user navigates through records (it fires following a record change, once the user is on the record).
If you want this code to fire when the user enters data, you should also add the code to the After UPdate event of your form or the control.
ASKER
Works Perfectly, Thanks for your help!
ASKER
Thanks,