Results 1 to 2 of 2

Thread: Populate specific row in Access table based on Primary Key

  1. #1
    Join Date
    Aug 2010
    Posts
    6

    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


    Please help thanks

  2. #2
    Join Date
    Mar 2006
    Location
    Oklahoma City, OK
    Posts
    184
    Try:

    Code:
    Private Sub PrintInvoice_Click()
    DoCmd.OpenQuery "SubtotalUpdate"
    DoCmd.OpenQuery "InvoiceTotalAppend"
    DoCmd.RunSQL "update Invoices set DueDate=date()+30 where duedate is null and [InvoiceID] = [Forms]![Invoices]![InvoiceID]"
    
    DoCmd.OpenReport "Invoices", acViewPreview, , "[Invoices.InvoiceID] = [Forms]![Invoices]![InvoiceID]", acWindowNormal
    Note:
    If you want to add 1 month not 30 days then try this:

    Code:
    DoCmd.RunSQL "update Invoices set DueDate=DateAdd(""m"", 1, Date()) where duedate is null and [InvoiceID] = [Forms]![Invoices]![InvoiceID]"
    Boyd Trimmell aka HiTech Coach
    Microsoft MVP - Access Expert
    [SIGPIC][/SIGPIC]
    Office Programming 25+ years as a Software Developer specializing in:
    Business Process Management
    Accounting/Inventory Control
    Customer Relations Management (CRM)
    Electronic Data Interchange (EDI)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •