VBA code to Macro

VKKT
2StarLounger
Posts: 184
Joined: 13 Jun 2018, 07:50

VBA code to Macro

Post by VKKT »

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

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA code to Macro

Post by HansV »

Why do you want to use a macro? It would be easier to convert the existing macro to VBA.
Best wishes,
Hans

VKKT
2StarLounger
Posts: 184
Joined: 13 Jun 2018, 07:50

Re: VBA code to Macro

Post by VKKT »

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

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA code to Macro

Post by HansV »

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

VKKT
2StarLounger
Posts: 184
Joined: 13 Jun 2018, 07:50

Re: VBA code to Macro

Post by VKKT »

Thanks Hans, YES....it is working :clapping: :clapping: :clapping: :clapping:

You are a blessing to this group......

Regards,
VKKT