Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Darla is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2016
    Posts
    25

    dlookup on update query

    Hi everyone! I am trying to accomplish something, and I'm not sure if an update query is the right way to do it?



    I have a form with CheckoutID and Status as fields that are bound to the table tblSMP. I'm trying to run a query that updates the value of Status to "Yes" only on records in the table where CheckoutID is the same as what's on the currently loaded record in the form. I'm trying to add that criteria into the query and it doesn't find any records to update. Is this the wrong way to accomplish this? Is there a better way?

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I'm trying to add that criteria into the query and it doesn't find any records to update
    perhaps provide the code you are using to do this?

  3. #3
    Darla is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2016
    Posts
    25
    I know it's something dumb I'm missing.

    UPDATE tblSMP SET tblSMP.Status = "Yes"
    WHERE (((tblSMP.checkoutID)=[Forms]![frmCheck]![checkoutID]));

  4. #4
    AccessPower's Avatar
    AccessPower is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    165
    Code:
    Dim strUpdate As String
    
    
    strUpdate  = "UPDATE tblSMP Set Status='Yes' WHERE CheckoutID='" & Me.CheckoutID.Value & "';"
    DoCMD.RunSQL strUpdate
    Is this what you're looking for?

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    is the status field a yes/no field? yes/no fields are numeric.

    if so then try

    UPDATE tblSMP SET tblSMP.Status = Yes

  6. #6
    Darla is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2016
    Posts
    25
    It's not. It can be a number of things, the "yes" really makes no sense but it was like that when I got here

  7. #7
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Sounds like the right way to do it.
    Are you running this query from the nav pane when the form is open and a value is loaded into the textbox?
    When you run the query, are there any prompts or messages?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    Darla is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2016
    Posts
    25
    Quote Originally Posted by Micron View Post
    Sounds like the right way to do it.
    Are you running this query from the nav pane when the form is open and a value is loaded into the textbox?


    I am, and there are no errors, just a blank datasheet

  9. #9
    Darla is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2016
    Posts
    25
    Quote Originally Posted by AccessPower View Post
    Code:
    Dim strUpdate As String
    
    
    strUpdate  = "UPDATE tblSMP Set Status='Yes' WHERE CheckoutID='" & Me.CheckoutID.Value & "';"
    DoCMD.RunSQL strUpdate
    Is this what you're looking for?
    I get a data type mismatch in criteria expression error, and when I go to debug, the "DoCmd.RunSQL" row is highlighted.

  10. #10
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    try putting debug.print strupdate in the code before the problem line

    You can then copy and paste the SQL into a query in SQL design mode to see what the issue is

  11. #11
    AccessPower's Avatar
    AccessPower is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    165
    Ahh.... Maybe try this. I removed the quotes from the CheckoutID criteria.

    Dim strUpdate As String
    strUpdate = "UPDATE tblSMP Set Status='Yes' WHERE CheckoutID=" & Me.CheckoutID.Value & ";"
    DoCMD.RunSQL strUpdate

  12. #12
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    or place a value you know should be correct in your query statement instead of referring to the form control. If it works, something is wrong with the reference to the form control. Based on your first post, I figure this is not a control on a subform so I've avoided any suggestions for that (the reference would not be valid in that case).

  13. #13
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Also something else to check - is the status field in the tblSMP table a lookup field? If yes, then you need to be using a different value from 'yes' based on whatever the bound column is.

  14. #14
    Darla is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2016
    Posts
    25
    Nope, not a lookup field. I just can't see the disconnect here.

  15. #15
    Darla is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    May 2016
    Posts
    25
    Quote Originally Posted by AccessPower View Post
    Ahh.... Maybe try this. I removed the quotes from the CheckoutID criteria.

    Dim strUpdate As String
    strUpdate = "UPDATE tblSMP Set Status='Yes' WHERE CheckoutID=" & Me.CheckoutID.Value & ";"
    DoCMD.RunSQL strUpdate

    Perfect!!!! Thank you!!!!!!!!!!!!!

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

Similar Threads

  1. Replies: 4
    Last Post: 02-13-2016, 06:00 PM
  2. Update with a DLookup
    By Paul H in forum Queries
    Replies: 7
    Last Post: 05-16-2014, 08:05 AM
  3. Update Using Dlookup
    By Cap Heresy in forum Queries
    Replies: 6
    Last Post: 03-14-2013, 03:59 PM
  4. Replies: 1
    Last Post: 02-26-2013, 01:45 PM
  5. Update Function Like DLookup
    By EddieN1 in forum Access
    Replies: 1
    Last Post: 01-04-2013, 12:31 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