Update code (1 Viewer)

ZeidHaddad

Registered User.
Local time
Today, 04:02
Joined
Oct 29, 2019
Messages
44
Good morning everyone!
i have a problem regarding an update code, the code used to work just fine before i added a second update which is ( StrSQL = "UPDATE Dokumentation SET Name) inside where the first one stopped working but the second is working.
so Update "Table=Dokumentation" is working while Update "Table=Eigenerbestand" is not
My goal is to update two different tables at the same time using a save button ( on click event)

this is the 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 & "',Kunde_erreicht = '" & Me.txtKunde_erreicht & "',Anrede = '" & Me.txtAnrede & ",Bausparsumme_Versendet = " & Me.txtBausparsumme_versendet & "',Reaktion_Angebot = '" & Me.txtReaktion_Angebot & _
        "',Interesse = '" & Me.txtInteresse & ",Folgetermin = " & Me.txtFolgetermin & "',Ohne_Unterschrift = '" & Me.txtOhne_Unterschrift & _
        "',Fuer_Outbound_nutzbar = '" & Me.txtFuer_Outbound_nutzbar & "',Insign_Flexperto = '" & Me.txtInsign_Flexperto & _
        "',Kontaktweg = '" & Me.txtKontaktweg & _
        "',Berater_Beteiligung = '" & Me.txtBerater_Beteiligung & "',Tarif_versendet = '" & Me.txtTarif_versendet & "',Neue_Vertragsnummer = '" & Me.txtNeue_Vertragsnummer & _
        "',Vetrag_eingerichtet = '" & Me.Vetrag_eingerichtet & "',Anruf_1 = '" & Me.txtAnruf_1 & ",Bausparsumme_angelegt = " & Me.Bausparsumme_angelegt & "',Datum_Neuabschluss = '" & Me.txtNeu_Abschluss & _
        "',Anruf_2 = '" & Me.txtAnruf_2 & _
        "',Anruf_3 = '" & Me.txtAnruf_3 & _
        "',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 & _
        "',notiz = '" & Me.txtnotiz & _
        "',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
 

isladogs

MVP / VIP
Local time
Today, 12:02
Joined
Jan 14, 2017
Messages
18,209
You keep posting new threads with the same code despite changes agreed/implemented earlier.

For example, back in an earlier thread, https://www.access-programmers.co.uk/forums/showthread.php?t=308359, it was established that Anruf_2 and Anruf_3 were date fields and I advised you how to handle those at the time using # delimiters.

Now you have again reverted to the original code. Why?
 

ZeidHaddad

Registered User.
Local time
Today, 04:02
Joined
Oct 29, 2019
Messages
44
good question.

when i changed them into date and time in every table they caused a lot of problem and stopped saving in the target table we had to change back to text.
 

isladogs

MVP / VIP
Local time
Today, 12:02
Joined
Jan 14, 2017
Messages
18,209
I would have advised fixing the original issue and continuing to use a datetime field for dates
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:02
Joined
Sep 21, 2011
Messages
14,234
Firstly debug.print the second strsql string.
Then walk through the code line by line as the second is in the Else path of the code, so you do one OR the other.?
 

ZeidHaddad

Registered User.
Local time
Today, 04:02
Joined
Oct 29, 2019
Messages
44
Firstly debug.print the second strsql string.
Then walk through the code line by line as the second is in the Else path of the code, so you do one OR the other.?

Hey so i deleted the whole thing with the else and this is the code now

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 & "',Kunde_erreicht = '" & Me.txtKunde_erreicht & "',Anrede = '" & Me.txtAnrede & ",Bausparsumme_Versendet = " & Me.txtBausparsumme_versendet & "',Reaktion_Angebot = '" & Me.txtReaktion_Angebot & _
        "',Interesse = '" & Me.txtInteresse & ",Folgetermin = " & Me.txtFolgetermin & "',Ohne_Unterschrift = '" & Me.txtOhne_Unterschrift & _
        "',Fuer_Outbound_nutzbar = '" & Me.txtFuer_Outbound_nutzbar & "',Insign_Flexperto = '" & Me.txtInsign_Flexperto & _
        "',Kontaktweg = '" & Me.txtKontaktweg & _
        "',Berater_Beteiligung = '" & Me.txtBerater_Beteiligung & "',Tarif_versendet = '" & Me.txtTarif_versendet & "',Neue_Vertragsnummer = '" & Me.txtNeue_Vertragsnummer & _
        "',Vetrag_eingerichtet = '" & Me.Vetrag_eingerichtet & "',Anruf_1 = '" & Me.txtAnruf_1 & ",Bausparsumme_angelegt = " & Me.Bausparsumme_angelegt & "',Datum_Neuabschluss = '" & Me.txtNeu_Abschluss & _
        "',Anruf_2 = '" & Me.txtAnruf_2 & _
        "',Anruf_3 = '" & Me.txtAnruf_3 & _
        "',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 & _
        "',notiz = '" & Me.txtnotiz & _
        "',Datum_letzter_Zahlungseingang = '" & Me.txtDatum_Letzter & _
        "' WHERE Vertragsnummer = '" & Me.Vertragsnummer & "'"
       
        

        CurrentDb.Execute StrSQL, dbFailOnError
 
         
 
        Debug.Print StrSQL
        If Me.Vertragsnummer = DLookup("[Vertragsnummer]", "Eigenerbestand", "[Vertragsnummer] = '" & Me.Vertragsnummer & "'") Then
        
        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 & "'"
        Debug.Print StrSQL
        CurrentDb.Execute StrSQL, dbFailOnError
    
    DoCmd.RunCommand acCmdSaveRecord
End If
    
    DoCmd.RunCommand acCmdSaveRecord
    End If
    DoCmd.Close
    DoCmd.Close acForm, "Eigenerbestand_lists"
    
speichern_Click_Exit:
    Exit Sub

speichern_Click_Err:
    MsgBox Error$
    Resume speichern_Click_Exit
End Sub

in the direct window it's giving the correct info but still not Updating the table "Eigenerbestand"
 
Last edited:

Users who are viewing this thread

Top Bottom