Private Sub cmdSave_Click()
'////////////////////////////////////////////////////////////////
'// Subroutine: cmdSave_Click
'////////////////////////////////////////////////////////////////
'// Author: Tranchemontaigne
'////////////////////////////////////////////////////////////////
'// Created:
'// 2 July 2008
'////////////////////////////////////////////////////////////////
'// Modified:
'// Date Editor Description
'// ---------------------------------------------------------
'// 26 Sep 2008 Tranchemontaigne Added error checking
'// 15 Dec 2008 Tranchemontaigne Modified to support record
'// edits
'/////////////////////////////////////////////////////////////////
'// Description:
'// Error checking
'// Confirm intent to save record
'// Save record
'// Log transaction
'//
'/////////////////////////////////////////////////////////////////
'// Library References:
'// Visual Basic for Applications
'// Microsoft Access 9.0 Object Library
'// fnLogError (ErrorLog module)
'// fnGet_UserID (WindowsAPI module)
'/////////////////////////////////////////////////////////////////
On Error GoTo Err_cmdSave_Click
Dim lngAnswer As Long
Dim strSQL As String
Dim lngAgreement As Long
Dim strPriority As String
Dim strDate As String
Dim lngProcess_Flow_ID As Long
Dim lngTask_ID As Long
Dim lngTRP As Long
Dim strComment As String
Dim strDescription As String
Dim rst1 As ADODB.Recordset
'error checking
If IsNull(Forms![frmEdit_Event]![cboPriority].Value) = True Then
MsgBox "Please specify the current priority of this agreement"
Forms![frmEdit_Event]![cboPriority].SetFocus
Exit Sub
End If
If IsNull(Forms![frmEdit_Event]![txtDate].Value) = True Then
MsgBox "Please enter the date this event happened"
Forms![frmEdit_Event]![txtDate].SetFocus
Exit Sub
End If
If IsNull(Forms![frmEdit_Event]![lboTask].Value) = True Then
MsgBox "Please select the task that has been completed"
Forms![frmEdit_Event]![lboTask].SetFocus
Exit Sub
End If
If IsNull(Forms![frmEdit_Event]![cboStaff_ID_TRP].Value) = True Then
MsgBox "Please select the person who completed this task"
Forms![frmEdit_Event]![cboStaff_ID_TRP].SetFocus
Exit Sub
End If
'confirm intent to add record
lngAnswer = MsgBox("You are about to record an event. " & _
"Do you wish to proceed?", vbYesNoCancel)
If lngAnswer = vbNo Then
MsgBox "Event was not saved"
DoCmd.Close acForm, "frmAdd_Events"
Exit Sub
ElseIf lngAnswer = vbCancel Then
Exit Sub
End If
'save event
'set variables
lngAgreement = [Forms]![frmEdit_Event]![cboAgreement_ID].Value
strPriority = [Forms]![frmEdit_Event]![cboPriority].Value
strDate = [Forms]![frmEdit_Event]![txtDate].Value
lngTask_ID = [Forms]![frmEdit_Event]![lboTask].Value
lngTRP = [Forms]![frmEdit_Event]![cboStaff_ID_TRP].Value
If IsNull([Forms]![frmEdit_Event]![txtComment].Value) = True Then
strComment = ""
Else
strComment = fnRemoveIllegalCharacters([Forms]![frmEdit_Event]![txtComment].Value)
End If
'detemine process flow ID
'define recordset
strSQL = "SELECT "
strSQL = strSQL & "t07_Process_Flow.t07_Process_Flow_ID, "
strSQL = strSQL & "t07_Process_Flow.t07_Task_No "
strSQL = strSQL & "FROM "
strSQL = strSQL & "t07_Process_Flow "
strSQL = strSQL & "WHERE "
strSQL = strSQL & "("
strSQL = strSQL & "("
strSQL = strSQL & "(t07_Process_Flow.t07_Process_Flow_ID)="
strSQL = strSQL & [Forms]![frmEdit_Event]![lboTask]
strSQL = strSQL & ")"
strSQL = strSQL & ")"
strSQL = strSQL & ";"
'build recordset
Set rst1 = New ADODB.Recordset
rst1.ActiveConnection = CurrentProject.Connection
rst1.Open strSQL
'set variables
lngProcess_Flow_ID = rst1![t07_Process_Flow_ID].Value
lngTask_ID = rst1![t07_Task_No].Value
'build update query
strSQL = "UPDATE "
strSQL = strSQL & "t08_Events "
strSQL = strSQL & "SET "
strSQL = strSQL & "t08_Events.t08_Priority = "
strSQL = strSQL & strPriority
strSQL = strSQL & ", "
strSQL = strSQL & "t08_Events.t08_Date = "
strSQL = strSQL & "#" & strDate & "#"
strSQL = strSQL & ", "
strSQL = strSQL & "t08_Events.t08_Process_Flow_ID = "
strSQL = strSQL & lngProcess_Flow_ID
strSQL = strSQL & ", "
strSQL = strSQL & "t08_Events.t08_Task_No = "
strSQL = strSQL & lngTask_ID
strSQL = strSQL & ", "
strSQL = strSQL & "t08_Events.t08_Staff_ID_TRP = "
strSQL = strSQL & lngTRP
strSQL = strSQL & ", "
strSQL = strSQL & "t08_Events.t08_Comment = "
strSQL = strSQL & Chr(34) & strComment & Chr(34)
strSQL = strSQL & ", "
strSQL = strSQL & "t08_Events.t08_Logged_By = "
strSQL = strSQL & Chr(34) & fnGet_UserID() & Chr(34)
strSQL = strSQL & " WHERE "
strSQL = strSQL & "("
strSQL = strSQL & "("
strSQL = strSQL & "(t08_Events.t08_Events_ID)="
strSQL = strSQL & [Forms]![frmEdit_Event]![txtAgreement]
strSQL = strSQL & ")"
strSQL = strSQL & ")"
strSQL = strSQL & ";"
'save edits
MsgBox "edits to t08-Events are problematic"
Debug.Print "t08-Events strSQL update: " & Chr(10) & strSQL & Chr(10)
'Call fnRunSQL(strSQL)
DoCmd.RunSQL strSQL
'log transaction in t08_Events
'build transaction description
strDescription = lngAgreement
strDescription = strDescription & "|Priority = "
strDescription = strDescription & strPriority
strDescription = strDescription & "|Date = "
strDescription = strDescription & strDate
strDescription = strDescription & "|Process_Flow_ID = "
strDescription = strDescription & lngProcess_Flow_ID
strDescription = strDescription & "|Task_ID = "
strDescription = strDescription & lngTask_ID
strDescription = strDescription & "|TRP = "
strDescription = strDescription & lngTRP
strDescription = strDescription & "|Comment = "
strDescription = strDescription & strComment
'log entry
Call fnLogTransaction("UPDATE", "t08_Events", [Forms]![frmEdit_Event]![txtAgreement], strDescription)
'housekeeping
DoCmd.Close acForm, "frmEdit_Event"
Set rst1 = Nothing
'Update master contract record
strSQL = "UPDATE "
strSQL = strSQL & "t04_Agreement_Master "
strSQL = strSQL & "SET "
strSQL = strSQL & "t04_Agreement_Master.t04_Process_Flow_ID = "
strSQL = strSQL & lngProcess_Flow_ID
strSQL = strSQL & ", "
strSQL = strSQL & "t04_Agreement_Master.t04_Status_Date = "
strSQL = strSQL & "#" & strDate & "#"
strSQL = strSQL & ", "
strSQL = strSQL & "t04_Agreement_Master.t04_Priority = "
strSQL = strSQL & strPriority
strSQL = strSQL & " WHERE "
strSQL = strSQL & "("
strSQL = strSQL & "("
strSQL = strSQL & "(t04_Agreement_Master.t04_Agreement_ID)="
strSQL = strSQL & lngAgreement
strSQL = strSQL & ")"
strSQL = strSQL & ")"
strSQL = strSQL & ";"
Debug.Print "t04_Agreement_Master strSQL update: " & Chr(10) & strSQL & Chr(10)
Call fnRunSQL(strSQL)
'log transaction in t04_Agreement_Master
'build transaction description
strDescription = lngAgreement
strDescription = strDescription & "|Priority = "
strDescription = strDescription & strPriority
strDescription = strDescription & "|Date = "
strDescription = strDescription & strDate
strDescription = strDescription & "|Process_Flow_ID = "
strDescription = strDescription & lngProcess_Flow_ID
'log entry
Call fnLogTransaction("UPDATE", "t04_Agreement_Master", lngAgreement, strDescription)
'update display
With [Forms]![frmMainMenu]![frmSubform].Form
![t04_Priority].Value = strPriority
![cboProcess_Flow_ID] = lngProcess_Flow_ID
![txtStatus_Date] = strDate
![subfrmEvents].Requery
End With
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Call fnLogError(gstrObject, "cmdSave_Click", Err.Description)
Resume Exit_cmdSave_Click
End Sub