Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185

    Update Query

    Hi,

    I have been trying to get this update query to work. I am looking for any ideas? This query updates my History pending table with recent shipped history. There is data in this shipped history by store item table copy, but every time I run the query it updates 0 rows in History Pending. Here is my SQL if that helps?

    UPDATE [DM-History-Pending] INNER JOIN [DM-ShipHistoryByStoreItem] ON ([DM-History-Pending].Store = [DM-ShipHistoryByStoreItem].Store) AND ([DM-History-Pending].Items = [DM-ShipHistoryByStoreItem].Item)

    SET [DM-History-Pending].[30-Shipped] = IIf([DM-ShipHistoryByStoreItem]![30]>0,[DM-ShipHistoryByStoreItem]![30],Null), [DM-History-Pending].[60-Shipped] = IIf([DM-ShipHistoryByStoreItem]![60]>0,[DM-ShipHistoryByStoreItem]![60],Null), [DM-History-Pending].[90-Shipped] = IIf([DM-ShipHistoryByStoreItem]![90]>0,[DM-ShipHistoryByStoreItem]![90],Null), [DM-History-Pending].[120-Shipped] = IIf([DM-ShipHistoryByStoreItem]![120]>0,[DM-ShipHistoryByStoreItem]![120],Null), [DM-History-Pending].[150-Shipped] = IIf([DM-ShipHistoryByStoreItem]![150]>0,[DM-ShipHistoryByStoreItem]![150],Null), [DM-History-Pending].[180-Shipped] = IIf([DM-ShipHistoryByStoreItem]![180]>0,[DM-ShipHistoryByStoreItem]![180],Null);

    This code used to work but I may have modified it to where it doesn't now. Thank you for any help.

  2. #2
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185
    I am also dealing with a module that runs a combination of queries to get this history pending. I am now getting the Update Query to at least say its going to update rows but when it goes to update there is a failure when it runs and does not update any row. Just wondering what would normally cause this?

    Thanks,
    Nick

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Perhaps your answer is in this link: http://allenbrowne.com/ser-61.html

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Your Update statement is updating a multi-table query; if this query is not updatable, the SQL update won't work. You might be able to make it updatable by putting indexes on [DM-ShipHistoryByStoreItem].Store and [DM-ShipHistoryByStoreItem].Item.

    To check if the query is updatable, put this into query design view, and see if you can make changes when you run it:

    SELECT [DM-History-Pending] INNER JOIN [DM-ShipHistoryByStoreItem] ON ([DM-History-Pending].Store = [DM-ShipHistoryByStoreItem].Store) AND ([DM-History-Pending].Items = [DM-ShipHistoryByStoreItem].Item)

  5. #5
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185
    Thanks, I am trying to fully understand the word index. I will try to make the change. I have a stand alone table also that works but I just can't get those numbers to update to the main table.

  6. #6
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185
    It looks like both store and item have Primary Keys. My process works by making a singular table and syncing it to Excel. I also changed that update query to a select query and it brought up a table with no values but had all the columns named and I could add info manually.

  7. #7
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185
    Quote Originally Posted by John_G View Post
    Your Update statement is updating a multi-table query; if this query is not updatable, the SQL update won't work. You might be able to make it updatable by putting indexes on [DM-ShipHistoryByStoreItem].Store and [DM-ShipHistoryByStoreItem].Item.

    To check if the query is updatable, put this into query design view, and see if you can make changes when you run it:

    SELECT [DM-History-Pending] INNER JOIN [DM-ShipHistoryByStoreItem] ON ([DM-History-Pending].Store = [DM-ShipHistoryByStoreItem].Store) AND ([DM-History-Pending].Items = [DM-ShipHistoryByStoreItem].Item)
    I was able to put indexes on both [DM-ShipHistoryByStoreItem].Store and [DM-ShipHistoryByStoreItem].Item. I set it to allow duplicates. Is this what you mean by indexing? It did not work for me so far.

  8. #8
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185
    I have also noticed that the table DM-History-Pending that I am trying to update is blank in the records that I am trying to update. The default value is zero but when information is queried and appended to the DM-History-Pending the Columns I want updated in the next update query become blank. Is this a problem?

  9. #9
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    ShipHistoryByStoreItem].Item)I was able to put indexes on both [DM-ShipHistoryByStoreItem].Store and [DM-ShipHistoryByStoreItem].Item. I set it to allow duplicates. Is this what you mean by indexing?
    Yes, that is what I meant. Since that didn't work, it means there is something else causing the problem - see below.


    ...the Columns I want updated in the next update query become blank. Is this a problem?
    No, not necessarily. But it does suggest that the update query is putting Null values where it shouldn't.

    Try this -
    For the columns in DM-History-Pending where you have set the default to zero, set Required = Yes and Allow Zero Length = No.

    You will have to use an update query to change any Nulls to 0 first (Numeric fields cannot contain zero-length strings anyway) , otherwise Access won't let you make those changes.


    If you are running the update query in VBA, add the Option dbFailOnError to the statement that executes them:
    currentDb.Execute "Update.....", dbFailOnError

    This will generate an error message if the query fails. If you are running the query from the Query Design screen, the changes I suggested above should cause an err message if it tries to update those fields to Null.

  10. #10
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185
    Thank You for replying. I will give it a shot.

  11. #11
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185
    OK, I was just looking and it seems to me that I have a number field instead of a text field could this be the issue? I did not see the allow zero length so I messed around with the data type and changed it to text? I changed the required to yes and the data violates the new rule.

  12. #12
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185
    I have also tried to append the zeros to the columns before I ran the update and it would still not update and the columns I put zeros in went blank.

  13. #13
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I have a number field instead of a text field could this be the issue?
    No, not directly. Leave it it as a number field if that is the type of data it contains. You won't see an Allow Zero Length property for numeric fields because it doesn't apply.

    I changed the required to yes and the data violates the new rule.
    Yes, it probably does. You have to replace the Nulls with zero's before you change the Required property to Yes.

    I have also tried to append the zeros to the columns before I ran the update and it would still not update
    Sounds like you might be trying to do that in the query. Instead, do it directly in the table so that you don't have to worry about problems related to linked tables.

    PS - do you have any relationships defined in the database (Database Tools - Relationships)?

  14. #14
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185
    Yes, I do have relationships set up between DM-ShipHistoryByStoreItem and DM-History-Pending the "Store" field and the "Items" fields are related.
    Attached Thumbnails Attached Thumbnails Relationships.jpg  

  15. #15
    nick243 is offline Competent Performer
    Windows 7 64bit Access 2002
    Join Date
    May 2016
    Posts
    185
    Sorry about the picture kind of hard to tell my relations ships. I can try to crop it out.

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

Similar Threads

  1. Query Update/Select Query (Wont Update)
    By NickWren in forum Access
    Replies: 1
    Last Post: 03-30-2016, 10:41 AM
  2. Replies: 14
    Last Post: 08-12-2014, 06:33 AM
  3. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  4. Replies: 2
    Last Post: 08-30-2012, 07:59 AM
  5. Replies: 4
    Last Post: 11-10-2011, 03:41 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