Results 1 to 10 of 10
  1. #1
    usfarang is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    42

    SQL Update Syntax

    Trying to update a table that may not have a value in the field. No errors just no results.

    DoCmd.RunSQL "UPDATE tblattempts SET tblattempts.userID = Me.txtUserID " & _
    "WHERE (((tblUsers.userID)='" & Me.txtUserID.Value & "'));"


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Concatenate variables.

    If you want to update a table with data from another table, really need a JOIN. Should probably show sample data and desired result.

    Is userID a text or number field in each table? Should probably be number. Don't use apostrophe delimiters for number type.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    usfarang is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    42
    This is an unbound form. userID is a text field in both tables.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I didn't ask if form is unbound - really irrelevant.

    You may have read my post before I edited. Review again.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    usfarang is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    42
    This is all I have. it is on frmLogin as I said is unbound which you said is irrelevant. But just FYI is all.
    tblattemptsAttemptsID PK
    userID = TEXT




    tblUsers
    userID = TEXT




    DoCmd.RunSQL "UPDATE tblattempts SET tblattempts.userID = Me.txtUserID " & _
    "WHERE (((tblUsers.userID)='" & Me.txtUserID.Value & "'));"

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Seems to me you really want to INSERT new records into tblAttempts.

    As I said, an UPDATE really should have JOIN clause.

    Why would UserID be empty in tblAttempts?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    usfarang is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    42
    No attempts has been made to enter a wrong password on the form is why!
    Unsure about the Insert syntax but yes I agree that is what I need.

    Here is my attempt at it, no errors but does not work?

    Dim strSQL As String 'Log failed Login Attempts to tblattempts.
    strSQL = "INSERT INTO tblattempts (userID,ComputerName ) "
    strSQL = strSQL & "VALUES (Me.txtUserID & " & Me.txtComputerName & "')" & _
    "WHERE (((tblUsers.userID)='" & Me.txtUserID.Value & "'));"
    CurrentDb.Execute strSQL, dbFailOnError
    Last edited by usfarang; 03-03-2022 at 11:12 PM. Reason: Code

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Concatenation and apostrophes are not correct. WHERE clause is not needed.

    strSQL = "INSERT INTO tblattempts (userID, ComputerName) VALUES('" & Me.txtUserID & "', '" & Me.txtComputerName & "')"

    If you bound form to tblAttempts and moved to new record row, SQL would not be needed, just:

    Me!UserID = Me.txtUserID
    Me!ComputerName = Me.txtComputerName
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by usfarang View Post
    No attempts has been made to enter a wrong password on the form is why!
    Unsure about the Insert syntax but yes I agree that is what I need.

    Here is my attempt at it, no errors but does not work?
    I am going to go to my grave saying this.

    Put the sql text into a sql string. Then you can debug.print it until you get it correct. Then you can use it in the SQL command.

    If you still cannot see the error, you can post here or elsewhere?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    usfarang is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    42
    Thanks for the help June and Welshgasman. I went a different route and all is well.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-16-2018, 01:18 PM
  2. update statement syntax
    By samos1023 in forum Programming
    Replies: 4
    Last Post: 05-24-2018, 03:09 PM
  3. Update Syntax
    By jrbmagoo in forum Forms
    Replies: 4
    Last Post: 08-08-2016, 07:36 AM
  4. Update syntax
    By looloo in forum Programming
    Replies: 6
    Last Post: 09-23-2011, 07:58 PM
  5. sql UPDATE syntax help
    By ducthang88 in forum Programming
    Replies: 1
    Last Post: 12-04-2010, 12:12 PM

Tags for this Thread

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