Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Brugge, Belgium
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trouble with adding records to a table (MS access 2007)

    In my database i retrieve from two distinguisch emails, the attachment, each containing an Access table ,each with the same structure.
    These two tables contains records with the following fields: KnltID, Agentnr, Artnr, Qty
    Each of these tables comes in in my database, after which i construct a unionquery "qryMailOrders", to put all the records of both tables together.
    After that i construct a recordset rstMailOrders("qryMailOrders", dbOpenDynaset)
    The goal is to get the records (the fields "KlntID", "Agentnr" ) out of this dynaset and add them to my table " tblorders", and the fields Artnr and Qty in my table "tblOrderdetails".
    In order to add the records to the table tblOrders, i construct a recordset rstOrder("qryOrders",dbOpendynaset)
    then i use the following code:

    lngCounter = acbGetCounter("tblOrdersID") = getting a new ordernr for the added record )
    OrderNr = Trim(Str(lngCounter) & "/" & Trim(Right(Date$, 2)))
    rstOrders.AddNew
    rstOrders!OrderID = OrderNr
    rstOrders!Orderdatum = Date
    rstOrders!KlntID = rstMailOrders!KlntID
    rstOrders!Agentnr = rstmailorders!Agentnr
    rstOrders.Update

    Running the code doesn't result in generating an error, but when i look to the tblOrders after running the code,
    no new record is added.
    What's wrong with this code ?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Trouble with adding records to a table (MS access 2007)

    Does qryMailOrders return any records?
    Is qryOrders updateable?

  3. #3
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Brugge, Belgium
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trouble with adding records to a table (MS access 2007)

    Dear Hans ; Could it be possible thatt the code don't work because there exists a referential integraty between tblorders and tblorderdetails, and that the code doesn't add a record to tblorderdetails ?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Trouble with adding records to a table (MS access 2007)

    You should be able to add a record to tblOrders before there is a corresponding record in tblOrderDetails.
    But you can't add a record to tblOrderDetails if the corresponding order hasn't been created yet in tblOrders.

  5. #5
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Brugge, Belgium
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trouble with adding records to a table (MS access 2007)

    thank you for the advice

Posting Permissions

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