Hello Khalid,
If I understand what you are asking ... I use a general procedure to update what you are calling "LastUpdate" with an optional Yes/No parameter (default is false) whether to update the parent (form) too -- then the record in the main form can have an edit date reflecting what was changed by subforms (records in related tables) too.
here is some sample code:
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ call in each Form BeforeUpdate event
Function FormBeforeUpdate( _
pF As Form _
, Optional bUpdateParentToo As Boolean = False _
) As Boolean
'121116, 151216 strive4peace
' call on the form BeforeUpdate event
'UPDATE the record on the current form with dtmEdit
' optionally, also update the record in the parent form
'
On Error GoTo Proc_Err
FormBeforeUpdate = False
' Dim nUserID As Long
' nUserID = CurrentDb.Properties("local_UserID")
With pF
!dtmEdit = Now()
If bUpdateParentToo Then
.Parent.dtmEdit = Now()
' .Parent!IDedit = nUserID
End If
If .NewRecord Then
' !IDadd = nUserID
Exit Function
End If
' !IDedit = nUserID
End With
FormBeforeUpdate = True
Proc_Exit:
On Error Resume Next
Exit Function
Proc_Err:
MsgBox Err.Description, , _
"ERROR " & Err.Number _
& " FormBeforeUpdate"
Resume Proc_Exit
Resume
End Function
WHERE:
dtmEdit is the date/time edited (your "LastUpdate").
There are some other lines commented to track user who added record or made change. I keep track of user with a database property.
respectfully,
crystal
http://www.MsAccessGurus.com
connect to me, let's build it together
~ have an awesome day ~
John,
Record Source of form "Add New Member" is Table "Members" in this table i today added field "LastUpdate".
None of the subforms have field LastUpdate yet on the TabCtl. Each subforms Record Source is separate table.
As these all subforms have Default View--->Datasheet, will i have to create field "LastUpdate" for each subform and put it on its Detail Section and then for each forms Before Update Event put similar code as for Main form "Add New Member".
Am i right ?
Regards,Khalid
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
Khalid-
What is the Record Source of this form and the Record Source of each of the subforms on the tab control? Which tables have a LastUpdate field? If there are separate tables, you would need similar code for each of the forms in the subform controls.
John Viescas, AuthorEffective SQLSQL Queries for Mere MortalsMicrosoft Access 2010 Inside OutMicrosoft Access 2007 Inside OutMicrosoft Access 2003 Inside OutBuilding Microsoft Access Applications(Paris, France)
On Jun 3, 2017, at 7:13 PM, Khalid Tanweer khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Hi John,
Hope you would be fine and all others in the Group.
I have a form "Add New Member" Default View--> Single Form.
I have put a new Text Control on its Footer "LastUpdate" Format Short Date. Visible=Yes
Forms Before Update Event is:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim msg As String
msg = msg & "Do you want to Save this record?"
If MsgBox(msg, vbYesNo, "SAC Pakistan Guide - Confirmation!") = vbYes Then
DoCmd.Save
If Me.MembershipExpireDate < Now Then
Me.SocietyLeavingReason = "Dormant"
Me.SocietyLeavingDate = MembershipExpireDate
Me.Working = False
LabelWorking.BackColor = RGB(255, 0, 0)
LabelWorking.Caption = "Removed Member:"
Me.LastUpdate = Now
End If
If IsNull(MembershipExpireDate) Or MembershipExpireDate > Now Then
Me.SocietyLeavingReason = ""
Me.SocietyLeavingDate = ""
Working = True
LabelWorking.BackColor = RGB(0, 9900, 0)
LabelWorking.Caption = "Active Member:"
Me.LastUpdate = Now
End If
Else
Me.Undo
End If
End Sub
--------------------------------------Up to here it is OK.The form has a TabCtl "TabCtlMemberInfo" it has 7 Tabs and under each Tab there are separate forms with Default View-->Datasheet
Now the situation is that before me some one other entered data and now i am myself looking and updating the data. As information regarding members might have changed or previously entered wrong or some fields have missing entries. Therefore i have to call and contact each member one by one and get it confirm from member his information under each Tab/Form.
I need as on Main Form on Save i am updating "LastUpdate". These Forms should also in any way be shown "Last Updated".
How ? i am not getting the logic or design. Please help.
Regards,Khalid
Posted by: crystal 8 <strive4peace2008@yahoo.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (5) |
Tidak ada komentar:
Posting Komentar