Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2005
    Posts
    61

    Unanswered: Adding a record to a table

    Hello again,

    I am trying to add a record to a table but not able to do so. The form is related to one table but I am trying to add a record to a different table. I'm not sure how to open the table and add the record.

    The table has a list of Products and product codes. I need to add these records to the second table.

    Here is what I was trying to do.

    DoCmd.GoToRecord acDataTable, "Product_Listing", acNewRec
    Product_Listing.AddNew
    Product_Listing!CSR_U_Number = strGlobalCSRUNumber
    Product_Listing.Update

    But I receive the error message the object 'Product_Listing' isn't open.

    Thanks for your help

  2. #2
    Join Date
    Apr 2005
    Posts
    61

    Anyone have any ideas?

    Anyone know how to do this in vbscript? I am need to update two tables in vbscript with the global variable that I've created but I need to open the second table some how and add the record.

    Thanks for your help

  3. #3
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    is there a reason not to do this directly with SQL?

    for a single append:
    dim strSQL as string
    strSQL = "INSERT INTO [Product_Listing] (CSR_U_Number) " _
    & "VALUES ('" & strGlobalCSRUNumber & "');"
    currentdb.execute strSQL

    you mention that there is a table containing the stuff you want to append:
    dim strSQL as string
    strSQL = "INSERT INTO [Product_Listing] (CSR_U_Number) " _
    & "SELECT someField FROM someTable WHERE someCriteria;"
    currentdb.execute strSQL

    you also say you want to insert Products and Product Codes:
    dim strSQL as string
    strSQL = "INSERT INTO [Product_Listing] (ProdField, ProdCodeField) " _
    & "SELECT someProdField, someCodeField FROM someTable " _
    & "WHERE someCriteria;"
    currentdb.execute strSQL
    ...the italic stuff needs editing to suit your real fieldnames etc

    izy
    Last edited by izyrider; 01-12-06 at 03:55.
    currently using SS 2008R2

Posting Permissions

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