Results 1 to 2 of 2
  1. #1
    amegahed3 is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    9

    Writing values to Access

    Hi All,



    I'm trying to write values back to an access database from an open source mathematical programming language (called glpk) using ODBC. I succeeded in doing so in most variables except one. The problem is described below:

    The following code gets an error when writing the data:

    Code:
     
    table x3_iii {j in TF, k in C, p in P, t in T: x3[j,k,p,t]>0} OUT 'ODBC'
      'FileDSN=.\d2.dsn'
    
      'UPDATE ((Channels a INNER JOIN ChannelPeriodProducts b'
    'ON a.ChannelID = b.ChannelID)'
    'INNER JOIN TransformerTypes d'
    'on a.OriginFacilityID = d.FacilityID'
    'SET b.Quantity = ?'
      'WHERE d.TransformerTypeID = ?'
      'AND a.OriginFacilityID =?'
      '    AND b.ProductID = ?'
      '    AND b.PeriodID = ?':
      x3[j, k, p, t], j, k, p, t;
    Note that the sql is on multiple lines, because of a maximum strings limit in the glpk (but the way I used in the code is fine and worked without problems for writing other variables).

    Now, let me describe what I am basically trying to do: I'm trying to write the values for the variable x3[j,k,p,t] in its field "Quantity" in the table 'ChannelPeriodProducts'. The indices for that variable are j,k,p,t.

    The 'ChannelPeriodProducts' table has a "ChannelID", "PeriodID", "ProductID" and "Quantity" fields. The index t is corresponding to "PeriodID", the index p is corresponding to the field "ProductID", and the variable x3[j,k,p,t] itself, as I said, is corresponding to the field "Quantity".

    The 'Channels' table has a "ChannelID", "OriginFacilityID" and "DestinationFacilityID" fields. The index k is corresponding to the field "DestinationFacilityID". The "ChannelID" field in it is corresponding to the "ChannelID" in the 'ChannelPeriodProducts' table.

    Finally, the 'TransformerTypes' table has a "FacilityID" and a "TransformerTypeID" fields. The index k is corresponding to the field "TransformerTypeID". The "FacilityID" field in this 'TransformerTypes' table is corresponding to the 'DestinationFacilityID' field in the Channels table.

    Note that there are existing records in all tables, with the "Quantity" field in these records in the table 'ChannelPeriodProducts' empty (as it is to be filled by the output of the model).

    Hope it is clear. I'd REALLY appreciate any help telling me how I can modify the above code in order to do what I want to do as explained above, or even provide me with a different code that does what I want to do!

    Thanks a lot,

    Aly
    Last edited by amegahed3; 08-17-2010 at 03:55 PM.

  2. #2
    amegahed3 is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    9
    Well, after MANY trials and asking different people, I was able to get the correct code. Here it is for anyone's reference:

    table x3_iii {j in TF, k in C, p in P, t in T: x3[j,k,p,t]>0} OUT 'ODBC'
    'FileDSN=.\d2.dsn'


    'UPDATE ((Channels a INNER JOIN ChannelPeriodProducts b'
    'ON a.ChannelID = b.ChannelID)'
    'INNER JOIN TransformerTypes d'
    'on a.OriginFacilityID = d.FacilityID)'
    'INNER JOIN Customers cc'
    'on a.DestinationFacilityID=cc.FacilityID'

    'SET b.Quantity = ?'

    'WHERE d.TransformerTypeID = ?'
    'AND cc.FacilityID =?'
    ' AND b.ProductID = ?'
    ' AND b.PeriodID = ?':
    x3[j, k, p, t], j, k, p, t;


    Best,

    Aly

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

Similar Threads

  1. Writing ASP into a Data Access Page
    By nellb13 in forum Programming
    Replies: 0
    Last Post: 07-19-2010, 12:23 PM
  2. Writing Access functions
    By new2access123 in forum Programming
    Replies: 5
    Last Post: 02-06-2010, 10:47 PM
  3. Automatically Writing SQL From A Table
    By smitstev in forum Programming
    Replies: 1
    Last Post: 06-05-2009, 09:38 AM
  4. I need help writing a query statement
    By dking in forum Queries
    Replies: 1
    Last Post: 02-25-2009, 09:43 AM
  5. Force writing from the right in a field?
    By Looping in forum Forms
    Replies: 0
    Last Post: 01-23-2006, 03:03 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