Results 1 to 4 of 4
  1. #1
    NiMora is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Location
    Germany
    Posts
    17

    once again: some problems with the sql UPDATE statement

    Hey guys,



    I try it again.

    I have a string I get from outlook with the hole name (fist name, sure name) and I want to split it into two fields.

    actually it works, but the UPDATE of the database won´t work. could you take a look please?

    Code:
    Option Compare DatabaseOption Explicit
    
    
    Private Sub Befehl9_Click()
    Dim db As DAO.Database
    Dim strGlatt
    Dim strLaenge
    Dim strPosLeer
    Dim strLinkeSeite
    Dim strRechteSeite
    Dim strSQL
    Dim strID As Byte
    
    
    Set db = CurrentDb
    strID = Me.ID
    Debug.Print "die ID ist: " & strID
    
    
    strGlatt = Trim$(Me.ganzerName)
    strLaenge = Len(strGlatt)
    Debug.Print "gesamtlänge: " & strLaenge
    strPosLeer = InStr(strGlatt, " ")
    Debug.Print "Position Leerzeichen: " & strPosLeer
    
    
    strLinkeSeite = Left(strGlatt, strPosLeer - 1)
    Debug.Print "Linker Name: " & strLinkeSeite
    strRechteSeite = Right(strGlatt, strLaenge - strPosLeer)
    Debug.Print "Rechter Name: " & strRechteSeite
    
    
    db.Execute ("UPDATE Tabelle1 SET Vorname = '" & strLinkeSeite & "', Nachname = '" & strRechteSeite & "' WHERE ID = strID")
    
    
    Forms![formTabelle1].Requery
    
    
    End Sub
    I think the proleme is the WHERE part, isn´t so?

    thx

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You have to concatenate the ID variable into the string, much as you did with the other. If the data type of the field is numeric, you wouldn't want the single quotes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I would add a variable

    Dim sql as string

    and before your current db.execute add this line (I did edit your line of code)

    sql = "UPDATE Tabelle1 SET Vorname = '" & strLinkeSeite & "', Nachname = '" & strRechteSeite & "' WHERE ID = " & strID

    Then comment your current db.execute line

    Then add

    Debug.Print sql

    This will show you what Access thinks your SQL means.

  4. #4
    NiMora is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Location
    Germany
    Posts
    17
    Hey, thx for quick help.

    this one helps:

    Code:
    strSQL = "UPDATE Tabelle1 SET Vorname = '" & strLinkeSeite & "', Nachname = '" & strRechteSeite & "' WHERE ID = " & strID
    result of debug.print: UPDATE Tabelle1 SET Vorname = 'Max', Nachname = 'Mustermann' WHERE ID = 3

    It works now and I untderstand that one part of the statement is a string and another part (especially the ID) is a number and has to put outside the string.

    cool, thx again

Please reply to this thread with any new information or opinions.

Similar Threads

  1. or statement problems
    By kalkap in forum Queries
    Replies: 6
    Last Post: 03-04-2014, 09:08 AM
  2. Update query problems, please help!
    By angliojoe in forum Queries
    Replies: 1
    Last Post: 09-24-2012, 10:38 AM
  3. Replies: 11
    Last Post: 03-21-2012, 12:51 PM
  4. refresh update data problems
    By whm1 in forum Forms
    Replies: 1
    Last Post: 03-19-2010, 01:49 PM
  5. Problems with an If statement
    By slenish in forum Access
    Replies: 1
    Last Post: 03-10-2010, 09:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums