Greetings..
Hi all
I have created a macro for recording the modified date and time and the below VBA code which I need to use in one form. But I am not able to do that so, please help me to convert the below code to a macro, or is there any other way to do make this possible.
regards,
VKKT
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not Me.NewRecord Then
If MsgBox("Do you want to save changes?", vbQuestion + vbYesNo) = vbNo Then
Me.Undo
Cancel = True
End If
End If
End Sub
VBA code to Macro
-
- Administrator
- Posts: 78577
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: VBA code to Macro
Why do you want to use a macro? It would be easier to convert the existing macro to VBA.
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 184
- Joined: 13 Jun 2018, 07:50
Re: VBA code to Macro
Hi Hans,
Thanks..
I had done the conversion to VBA as below, but it is not working.
Regards,
VKKT
'------------------------------------------------------------
' LAST_MODIFIED
'
'------------------------------------------------------------
Function LAST_MODIFIED()
On Error GoTo LAST_MODIFIED_Err
With CodeContextObject
.TimeModified = Time()
.DateModified = DATE
End With
LAST_MODIFIED_Exit:
Exit Function
LAST_MODIFIED_Err:
MsgBox Error$
Resume LAST_MODIFIED_Exit
End Function
Thanks..
I had done the conversion to VBA as below, but it is not working.
Regards,
VKKT
'------------------------------------------------------------
' LAST_MODIFIED
'
'------------------------------------------------------------
Function LAST_MODIFIED()
On Error GoTo LAST_MODIFIED_Err
With CodeContextObject
.TimeModified = Time()
.DateModified = DATE
End With
LAST_MODIFIED_Exit:
Exit Function
LAST_MODIFIED_Err:
MsgBox Error$
Resume LAST_MODIFIED_Exit
End Function
-
- Administrator
- Posts: 78577
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: VBA code to Macro
Does this work?
Code: Select all
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not Me.NewRecord Then
If MsgBox("Do you want to save changes?", vbQuestion + vbYesNo) = vbNo Then
Me.Undo
Cancel = True
Exit Sub
End If
End If
Me.TimeModified = Time
Me.DateModified = Date
End Sub
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 184
- Joined: 13 Jun 2018, 07:50
Re: VBA code to Macro
Thanks Hans, YES....it is working
You are a blessing to this group......
Regards,
VKKT
You are a blessing to this group......
Regards,
VKKT