Results 1 to 2 of 2
  1. #1
    chrisjack001 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    12

    Populate specific row in Access table based on Primary Key

    I have this Form Called "Invoices" that I will input a "InvoiceID" number from a drop down combo and enter. This will populate the form. I will then click a print button that will trigger this code. What it does is it will update the Duedate field in the Invoices table if the field is blank with (Current date + 30) before opening the "Invoices" report in printview to print that specific report. What Im having problem with is the code goes through the whole "Invoices" table and updates any DueDate field that is blank which it should not be doing. It should just update that specific row with that InvoiceID that you input in the beginning which is the primary key. The code I have now is this and everything works except it updates all Duedate fields that are blank.

    Private Sub PrintInvoice_Click()


    DoCmd.OpenQuery "SubtotalUpdate"
    DoCmd.OpenQuery "InvoiceTotalAppend"
    DoCmd.RunSQL "update Invoices set DueDate=date()+30 where duedate is null"
    DoCmd.OpenReport "Invoices", acViewPreview, , "[Invoices.InvoiceID] = [Forms]![Invoices]![InvoiceID]", acWindowNormal
    End Sub

  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
    Your SQL tells it to update all that have a Null due date. If you only want to update a specific ID, change the WHERE clause in the SQL to one similar to your OpenReport wherecondition.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Using random fields in Excel to populate Access table
    By cryswater in forum Import/Export Data
    Replies: 3
    Last Post: 05-14-2013, 02:50 PM
  2. Populate primary key into imported tables
    By Edigo in forum Import/Export Data
    Replies: 0
    Last Post: 03-16-2010, 09:17 PM
  3. Replies: 1
    Last Post: 11-10-2009, 03:20 PM
  4. Replies: 2
    Last Post: 10-27-2009, 07:09 AM
  5. Replies: 2
    Last Post: 07-15-2009, 04:08 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