On the close of a form I have a series of codes that 'should' update a table with in the database with data from the fields on the form, the issue i have is that the update sql doesn't seem to work. Code is below, the highlighted bit is what doesn't seem to want to work.
Any help with this would be appreciated.
Didn't anyone ever tell you? There's one thing you never put in a trap — if you're smart, if you value your continued existence, if you have any plans about seeing tomorrow — there's one thing you never — ever, put in a trap. … Me.
Code:
Private Sub Command496_Click()
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
DoCmd.SetWarnings False
Dim Number As String
Number = Calls.Value
If Number = "1" Then Me.Call1_Outcome = CurrOutcome.Value Else
If Number = "2" Then Me.Call2_Outcome = CurrOutcome.Value Else
If Number = "3" Then Me.Call3_Outcome = CurrOutcome.Value Else
If Number = "4" Then Me.Call4_Outcome = CurrOutcome.Value Else
If Number = "5" Then Me.Call5_Outcome = CurrOutcome.Value Else
If Number = "6" Then Me.Call6_Outcome = CurrOutcome.Value Else
If Number = "7" Then Me.Call7_Outcome = CurrOutcome.Value Else
If Number = "8" Then Me.Call8_Outcome = CurrOutcome.Value Else
Dim change As String
If Me.CurrOutcome.Value = "1" Then change = "Accepted" Else
If Me.CurrOutcome.Value = "2" Then change = "Accepted in Store" Else
If Me.CurrOutcome.Value = "3" Then change = "Appointment" Else
If Me.CurrOutcome.Value = "4" Then change = "Appointment in store" Else
If Me.CurrOutcome.Value = "5" Then change = "Callback" Else
If Me.CurrOutcome.Value = "6" Then change = "Declined" Else
If Me.CurrOutcome.Value = "7" Then change = "Not Available" Else
If Me.CurrOutcome.Value = "8" Then change = "Wrong Number" Else
If Me.CurrOutcome.Value = "10" Then change = "Withdrawn" Else
If Me.CurrOutcome.Value = "11" Then change = "Contacting" Else
If Me.CurrOutcome.Value = "12" Then change = "Uncontactable" Else
Dim Adder As String
If IsNull(Me.Add_Out.Value) Then Adder = ""
If Me.Add_Out.Value = "1" Then Adder = "Voicemail" Else
If Me.Add_Out.Value = "2" Then Adder = "Engaged" Else
If Me.Add_Out.Value = "3" Then Adder = "No Answer" Else
If Me.Add_Out.Value = "4" Then Adder = "Callback - DMC" Else
If Me.Add_Out.Value = "5" Then Adder = "Callback - Non DMC" Else
If CurrOutcome <> "" And IsNull(Calls) Then
Msg = "You must add call attemps if you are adding an outcome"
Style = vbOKOnly + vbInformation + vbDefaultButton2
Title = "Brighthouse Data Added"
Help = ""
Ctxt = 1000
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
Else
If IsNull(CurrOutcome.Value) Then
Msg = "Do you want to exit without an outcome"
Style = vbYesNo + vbInformation + vbDefaultButton2
Title = "Brighthouse Data Added"
Help = ""
Ctxt = 1000
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then
'Forms!frmpersonContact.RecordSource = ""
'DoCmd.Close acForm, "frmPersonContact"
DoCmd.OpenQuery "Details_Temp Query"
DoCmd.RunSQL "Delete from Details_Temp where User = '" & fOSUserName & "';"
DoCmd.OpenQuery "Details_Temp_Update_2"
DoCmd.RunSQL "Delete from Details_Temp2 where User = '" & fOSUserName & "';"
'DoCmd.OpenForm "View_Data"
Forms!View_Data.Visible = True
Forms!View_Data!lstSearch.Requery
Forms!View_Data!Call_Att.Requery
Forms!View_Data!UserOnly.Requery
End If
Else
DoCmd.OpenQuery "Details_Temp Query"
DoCmd.RunSQL "Delete from Details_Temp where User = '" & fOSUserName & "';"
DoCmd.OpenQuery "Details_Temp_Update_2"
DoCmd.RunSQL "Delete from Details_Temp2 where User = '" & fOSUserName & "';"
Forms!View_Data.Visible = True
Forms!View_Data!lstSearch.Requery
Forms!View_Data!Call_Att.Requery
Forms!View_Data!UserOnly.Requery
End If
End If
Dim Result As String
Dim Result2 As String
Dim Result3 As String
Dim Result4 As String
If IsNull(Forms!frmpersonContact!Add_Out.Value) Then
Result3 = change 'Me.CurrOutcome.Value
Result2 = fOSUserName
Result = Result3 + " " + Result2
Else
Result3 = change 'Me.CurrOutcome.Value
Result4 = Adder 'Me.Add_Out.Value
Result2 = fOSUserName
Result = Result3 + " " + Result4 + " " + Result2
End If
Dim strSQL As String
Dim Column As String
Dim Date_Column As String
If Me.Calls.Value = "1" Then Column = "Call1_Comments" Else
If Me.Calls.Value = "1" Then Date_Column = "DandT_Call1" Else
If Me.Calls.Value = "1" Then Result = "Call 1: " & Result Else
If Me.Calls.Value = "2" Then Column = "Call2_Comments" Else
If Me.Calls.Value = "2" Then Date_Column = "DandT_Call2" Else
If Me.Calls.Value = "2" Then Result = "Call 2: " & Result Else
If Me.Calls.Value = "3" Then Column = "Call3_Comments" Else
If Me.Calls.Value = "3" Then Date_Column = "DandT_Call3" Else
If Me.Calls.Value = "3" Then Result = "Call 3: " & Result Else
If Me.Calls.Value = "4" Then Column = "Call4_Comments" Else
If Me.Calls.Value = "4" Then Date_Column = "DandT_Call4" Else
If Me.Calls.Value = "4" Then Result = "Call 4: " & Result Else
If Me.Calls.Value = "5" Then Column = "Call5_Comments" Else
If Me.Calls.Value = "5" Then Date_Column = "DandT_Call5" Else
If Me.Calls.Value = "5" Then Result = "Call 5: " & Result Else
If Me.Calls.Value = "6" Then Column = "Call6_Comments" Else
If Me.Calls.Value = "6" Then Date_Column = "DandT_Call6" Else
If Me.Calls.Value = "6" Then Result = "Call 6: " & Result Else
If Me.Calls.Value = "7" Then Column = "Call7_Comments" Else
If Me.Calls.Value = "7" Then Date_Column = "DandT_Call7" Else
If Me.Calls.Value = "7" Then Result = "Call 7: " & Result Else
If Me.Calls.Value = "8" Then Column = "Call8_Comments" Else
If Me.Calls.Value = "8" Then Date_Column = "DandT_Call8" Else
If Me.Calls.Value = "8" Then Result = "Call 8: " & Result Else
[highlight #CC0000]DoCmd.RunSQL "UPDATE Data_File SET " & Date_Column & "= Now() where ID = " & Me.Clientid & ""
DoCmd.RunSQL "UPDATE Data_File SET Last_Updated_Date = Now() where ID = " & Me.Clientid & ""
DoCmd.RunSQL "UPDATE Data_File SET Last_Updated_by = '" & fOSUserName & "' where ID = " & Me.Clientid & ""[/highlight]
If IsNull(Me.Comments_List) Then
Me.Comments_List = "" & Column & ": " & Result & "" & vbNewLine
Else
Me.Comments_List = Me.Comments_List + "" & Column & ": " & Result & "" & vbNewLine
End If
DoCmd.RunSQL "INSERT INTO Log_Table (User,Record_Id,What_Updated,Details,Updated_Date) Values ('" & fOSUserName & "','" & Me.Clientid & "','Comments','" & Result & "',Now())"
DoCmd.Close acForm, "frmPersonContact"
Forms!View_Data.Visible = True
Forms!View_Data!lstSearch.Requery
Forms!View_Data!Call_Att.Requery
Forms!View_Data!UserOnly.Requery
Forms!View_Data!Last5.Requery
Forms!View_Data!Callback.Requery
Forms!View_Data!PastCB.Requery
Forms!View_Data.Requery
Any help with this would be appreciated.
Didn't anyone ever tell you? There's one thing you never put in a trap — if you're smart, if you value your continued existence, if you have any plans about seeing tomorrow — there's one thing you never — ever, put in a trap. … Me.