Button Click and then Date/TimeStamp

blues763

Registered User.
Local time
Today, 23:08
Joined
Jun 30, 2014
Messages
17
Hi,

I'm new to access.
I have created a form that is bound to a table.

There is a button on the form that allows users to send email with the form as an attachment in pdf. I'd like to create a date/time stamp in another table called tblLog. Trouble is the code works uptil sending emails but it doesn't record the stamp.

Heres what I've done so far. Any help would be greatly appreciated

----------
Private Sub cmdEmail_Amd_Click()

On Error GoTo cmdEmail_Amd_Click_Err
DoCmd.OpenForm "frmAmendment_Master", , , "[Record_ID]=" & Me.Record_ID.Value
DoCmd.SendObject acForm, "frmAmendment_Master", "PDFFormat(*.pdf)", "", "", "", "Amendment Form" & " " & Surname & " " & Firstname, "", True, ""

cmdEmail_Amd_Click_Exit:
Exit Sub
cmdEmail_Amd_Click_Err:
MsgBox ("Email Operation Cancelled")
Resume cmdEmail_Amd_Click_Exit



Dim dbLog As DAO.Database
Dim LogRec As DAO.Recordset

Set dbLog = CurrentDb
Set LogRec = dbLog.OpenRecordset("tblLog")
LogRec.AddNew
LogRec("eDate").Value = Date
LogRec("eTime") = Format(Now, "Long Time")
LogRec("Form").Value = "frmAmendment_Master"
LogRec("User").Value = Me.[User Assignment_Amd].Value
LogRec("Detail").Value = User & "Opened Form"
LogRec.Update

End Sub
 
You have an 'exit sub' in the middle which means it does not run everything after it. So I think you want something more like:

Code:
Private Sub cmdEmail_Amd_Click()
 
On Error GoTo cmdEmail_Amd_Click_Err
DoCmd.OpenForm "frmAmendment_Master", , , "[Record_ID]=" & Me.Record_ID.Value
DoCmd.SendObject acForm, "frmAmendment_Master", "PDFFormat(*.pdf)", "",  "", "", "Amendment Form" & " " & Surname & " " &  Firstname, "", True, ""

Dim dbLog As DAO.Database
Dim LogRec As DAO.Recordset

Set dbLog = CurrentDb
Set LogRec = dbLog.OpenRecordset("tblLog")
LogRec.AddNew
LogRec("eDate").Value = Date
LogRec("eTime") = Format(Now, "Long Time")
LogRec("Form").Value = "frmAmendment_Master"
LogRec("User").Value = Me.[User Assignment_Amd].Value
LogRec("Detail").Value = User & " Opened Form"
LogRec.Update

cmdEmail_Amd_Click_Exit:
    Exit Sub
cmdEmail_Amd_Click_Err:
    MsgBox ("Email Operation Cancelled")
    Resume cmdEmail_Amd_Click_Exit

End Sub
Also on the line:
Code:
LogRec("Detail").Value = User & " Opened Form"
It doesn't look like 'User' has been defined as anything. Also I added a space at the start of your string, assuming User will be someone's name without a space on the end.
You probably want something like:
Code:
LogRec("Detail").Value = Environ("Username") & " Opened Form"
 
I thank you SIR!

Works fine now
 

Users who are viewing this thread

Back
Top Bottom