Update Code (1 Viewer)

ZeidHaddad

Registered User.
Local time
Today, 02:57
Joined
Oct 29, 2019
Messages
44
Good day to you all!

so i'm using this code to update my table "Dokumentation" but i noticed that it's not updating the table unless i remove the lines :

"',Anruf_2 = '" & Me.txtAnruf_2 & _
"',Anruf_3 = '" & Me.txtAnruf_3 & _

if the lines are inside the code nothing will update, however if i remove them and press the save button Again it will save with no problems.

Code:
Code:
Private Sub speichern_Click()
On Error GoTo speichern_Click_Err

    On Error Resume Next

    Dim MaxID As Variant
    Dim StrSQL As String
    If Me.Vertragsnummer = DLookup("[Vertragsnummer]", "Dokumentation", "[Vertragsnummer] = '" & Me.Vertragsnummer & "'") Then
        MsgBox ("Entry already exists - please save")
        
    
        StrSQL = "UPDATE Dokumentation SET Name = '" & Me.txtName & _
        "',Vorname = '" & Me.txtVorname & _
        "',Anruf_1 = '" & Me.txtAnruf_1 & _
        "',Anruf_2 = '" & Me.txtAnruf_2 & _
        "',Anruf_3 = '" & Me.txtAnruf_3 & _
        "',Kunde_erreicht = '" & Me.txtKunde_erreicht & _
        "',Anrede = '" & Me.txtAnruf_1 & _
        "',Geburtsdatum_KUNDE = '" & Me.txtGeburtsdatum_KUNDE & _
        "',TELEFONNR_Kunde = '" & Me.txtTELEFONNR & _
        "',E_Mail_Kunde = '" & Me.txtE_Mail & _
        "',Bausparsumme = '" & Me.txtBausparsumme & _
        "',Abschlussdatum = '" & Me.txtAbschlussdatum & _
        "',Saldo_EUR = '" & Me.txtSaldo_EUR & _
        "',Saldo_3112_Vorjahr_EUR = '" & Me.txtSaldo_3112_Vorjahr_EUR & _
        "',VL_Eingang = '" & Me.txtVL_Eingang & _
        "',Sollzins_Gebunden_Fest_JAEhrlic = '" & Me.TXTSollzins_Gebunden_Fest_JAEhrlic & _
        "',Tarifgeneration = '" & Me.txtTarifgeneration & _
        "',Tarif = '" & Me.txtTarif & _
        "',Datum_letzter_Zahlungseingang = '" & Me.txtDatum_Letzter & _
        "' WHERE Vertragsnummer = '" & Me.Vertragsnummer & "'"
       
        

        
        CurrentDb.Execute StrSQL, dbFailOnError
     Else
    MaxID = DMax("[FallNr]", "Dokumentation")
    If Not IsNull(MaxID) Then
    Me.FallNr = MaxID + 1
    End If
    
        StrSQL = "UPDATE Eigenerbestand SET Anruf_1 = '" & Me.txtAnruf_1 & "', Anruf_2 = '" & Me.txtAnruf_2 & "', Anruf_3 = '" & Me.txtAnruf_3 & "', Kunde_erreicht = '" & Me.txtKunde_erreicht & "'  WHERE Vertragsnummer = " & Me.Vertragsnummer & ""
    CurrentDb.Execute StrSQL, dbFailOnError
  
    End If
    
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.Close
    DoCmd.Close acForm, "Eigenerbestand_lists"
    
speichern_Click_Exit:
    Exit Sub

speichern_Click_Err:
    MsgBox Error$
    Resume speichern_Click_Exit
End Sub
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 02:57
Joined
Oct 29, 2018
Messages
21,449
Hi. For troubleshooting, add the line Debug.Print strSQL before executing the query, so you can see why it's not updating anything.
 

isladogs

MVP / VIP
Local time
Today, 10:57
Joined
Jan 14, 2017
Messages
18,209
What datatypes are the two 'problem' fields?
 

ZeidHaddad

Registered User.
Local time
Today, 02:57
Joined
Oct 29, 2019
Messages
44
Hi. For troubleshooting, add the line Debug.Print strSQL before executing the query, so you can see why it's not updating anything.

Should i add the line before "CurrentDb.Execute StrSQL, dbFailOnError"
 

isladogs

MVP / VIP
Local time
Today, 10:57
Joined
Jan 14, 2017
Messages
18,209
As they are both date/time you need to use # delimiters instead of single quote '

Code:
"',Anruf_2 = #" & Me.txtAnruf_2 & _
"#,Anruf_3 = #" & Me.txtAnruf_3 & _
"#,
 

moke123

AWF VIP
Local time
Today, 05:57
Joined
Jan 11, 2013
Messages
3,910
Should i add the line before "CurrentDb.Execute StrSQL, dbFailOnError"
Yes add it after the strSql and before .execute.
You can even comment out the execute line until your Sql is corrected.
 

ZeidHaddad

Registered User.
Local time
Today, 02:57
Joined
Oct 29, 2019
Messages
44
As they are both date/time you need to use # delimiters instead of single quote '

Code:
"',Anruf_2 = #" & Me.txtAnruf_2 & _
"#,Anruf_3 = #" & Me.txtAnruf_3 & _
"#,
i fixed this but still it's Not updating
 

ZeidHaddad

Registered User.
Local time
Today, 02:57
Joined
Oct 29, 2019
Messages
44
Yes add it after the strSql and before .execute.
You can even comment out the execute line until your Sql is corrected.

did this, i got the correct thing inside the Vba but still inside the table it's Not Updating
 

isladogs

MVP / VIP
Local time
Today, 10:57
Joined
Jan 14, 2017
Messages
18,209
Did you make the same changes in the other strSQL statement?
Do you have any number fields? If so, remove the single quotes for those.

Looking at the two statements, the WHERE line is different for each.
The first assumes the field is text. The second treats it as a number field. Both can't be right.

Do you have any null values to deal with?

If not already done, step through the code and check which line it fails on.
 

ZeidHaddad

Registered User.
Local time
Today, 02:57
Joined
Oct 29, 2019
Messages
44
Okay now it's Finally working. Thank You all for the Help!
 

Users who are viewing this thread

Top Bottom