The code for the date stamp is simple enough.
Private Sub CmdMyButton_Click()
txtThingDateStamped.Locked = False
txtThingDateStamped = Now()
txtThingDateStamped.Locked = True
End Sub
But users can still hit the date stamp multiple times and it can be edited by other forms.
I used the MS Access Project Management template to start my adventure here. Specifically the two forms I'm working with are (1) "Project Details" and (2) "Project List".
You could use a Before Change data macro on the table to enforce the constraint at that level:
<?xml version="1.0" encoding="utf-16" standalone="no"?>
<DataMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application">
<DataMacro Event="BeforeChange">
<Statements>
<ConditionalBlock>
<If>
<Condition>Updated("ThingDateStamped")</Condition>
<Statements>
<ConditionalBlock>
<If>
<Condition>Not IsNull([Old].[ThingDateStamped])</Condition>
<Statements>
<Action Name="RaiseError">
<Argument Name="Number">1</Argument>
<Argument Name="Description">An existing datestamp cannot be altered.</Argument>
</Action>
</Statements>
</If>
</ConditionalBlock>
</Statements>
</If>
</ConditionalBlock>
</Statements>
</DataMacro>
</DataMacros>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.