Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Office 365
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,739
    You can't use "AND" for naming multiple table field names, the separator is a comma.


    Code:
    Sub modque_addnewlocation() ' update query Dim db As DAO.Database
        Dim db As DAO.Database
        Set db = CurrentDb
        Dim dateDate As Date, strLineNo As String, strSQL As String
        Dim strSvc As String, lngProposalNo As Long
        dateDate = DateValue("9/27/2025")
        strLineNo = "104"
        strSvc = "stripe"
        lngProposalNo = 20250537
        strSQL = "UPDATE tblCalendar SET fLngProposalNo = " & lngProposalNo & ", " _
        & "fTxtService = '" & strSvc & "'" _
        & " WHERE DateValue(fDate) = #" & dateDate & "# AND fStrLineNo = '" & strLineNo & "'"
        Debug.Print strSQL
        db.Execute strSQL, dbFailOnError
    End Sub
    Immediate Pane: shows debug.print
    call modque_addnewlocation
    UPDATE tblCalendar SET fLngProposalNo = 20250537, fTxtService = 'stripe' WHERE DateValue(fDate) = #9/27/2025# AND fStrLineNo = '104'

    Result:
    Click image for larger version. 

Name:	stripe.png 
Views:	15 
Size:	13.9 KB 
ID:	53303
    Last edited by davegri; 10-02-2025 at 05:43 PM. Reason: mire

  2. #17
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    216
    I just got it. I have an AND in the set statement as follows:
    strSQL = "UPDATE tblCalendar SET fLngProposalNo = " & lngProposalNo & " AND " _

    It should have a comma instead.
    strSQL = "UPDATE tblCalendar SET fLngProposalNo = " & lngProposalNo & ", " _

    So the query now works. I appreciate everyone's help.

  3. #18
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    216
    Thank you davegri

  4. #19
    Gustav's Avatar
    Gustav is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2025
    Posts
    32
    You miss a space before WHERE and to use the correct syntax:
    Code:
    strSQL = "UPDATE tblCalendar " & _
        "SET fLngProposalNo = " & Str(lngProposalNo) & ", fTxtService = '" & strSvc & "' " & _
        "WHERE fDate = #" & Format(dateDate, "yyyy\/mm\/dd") & "# AND fStrLineNo = '" & strLineNo & "'"

  5. #20
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    FWIW I always put the space at the start of the next line. Easier to see than having to scroll to the right all the time.

    Code:
    strSQL = "UPDATE tblCalendar " & _
        " SET fLngProposalNo = " & Str(lngProposalNo) & ", fTxtService = '" & strSvc & "' " & _
        " WHERE fDate = #" & Format(dateDate, "yyyy\/mm\/dd") & "# AND fStrLineNo = '" & strLineNo & "'"
    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

  6. #21
    Join Date
    Sep 2025
    Location
    Newport, Shropshire, UK
    Posts
    16
    You can correct any rows which contain a non-zero tome of day element in the fDate column by executing the following update query:

    Code:
    UPDATE tblCalendar
    SET fDate = INT(fDate)
    WHERE fDate IS NOT NULL;
    Having done that set the ValidationRule property of the fDate column in table design view to:

    Int([fDate]) Or Is Null

    or, if the Required property of the column is True (Yes), to:

    Int([fDate])

    If you are still experiencing the same behaviour can you attach a copy of your file, with any personal or otherwise sensitive data disguised? All we really need is the tblCalendar table with the row in question, so you can copy and paste that into a new .accdb file if you do not want to expose your other data. The copy must be exhibiting the errant behaviour of course.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 01-24-2024, 06:10 PM
  2. I know what I need to do but don't know how to.
    By EVGData in forum Programming
    Replies: 2
    Last Post: 04-25-2016, 07:34 AM
  3. Replies: 6
    Last Post: 10-15-2014, 02:24 PM
  4. Replies: 10
    Last Post: 10-29-2013, 10:53 PM
  5. Replies: 12
    Last Post: 09-04-2013, 02:51 AM

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