Results 1 to 11 of 11

Thread: Reducing a field Quantity

  1. #1

    Thread Starter
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015

    Reducing a field Quantity

    I want to reduce a field quantity, by the quantity in another field, on another table. I am using the same data environment with bound controls for each. I figure I need to add that table to the query, but I'm not sure of the algorithm, nor where to put it. Can anyone point me in the right direction?

  2. #2
    Member
    Join Date
    Oct 2002
    Posts
    50
    You need to explain your setup more. Are you in VB? Access?

    in Access:
    Table1 has a number field called 'number' I want to replace this value with the 'age' value from table2. Based on the Id fields been equal. (you could use name).

    UPDATE Table1 INNER JOIN table2 ON Table1.ID = table2.ID SET Table1.[number] = [number]-[table2].[age];

    Adam.
    Last edited by adamgray1209; Nov 6th, 2002 at 11:18 AM.

  3. #3

    Thread Starter
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015
    Yeah, sorry. VB and Access. Are you saying this can be accomplished entirely in access, with no coding?

  4. #4
    Member
    Join Date
    Oct 2002
    Posts
    50
    Yes. Queries. Open new in design view. Add the 2 tables. Make the link. Menu>Query change to update query. doubleclick only the field you want to change, in the UpdateTo field, put [fieldYouHaveJustSelected] - [secondTableName].[fieldToTakeMinus] . Then select Menu>Query>Run. Be sure to copy your tables first in case of error!

    Adam.

  5. #5
    Member
    Join Date
    Oct 2002
    Posts
    50
    See this for help.
    Attached Files Attached Files

  6. #6
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Originally posted by adamgray1209
    Yes. Queries. Open new in design view. Add the 2 tables. Make the link. Menu>Query change to update query. doubleclick only the field you want to change, in the UpdateTo field, put [fieldYouHaveJustSelected] - [secondTableName].[fieldToTakeMinus] . Then select Menu>Query>Run. Be sure to copy your tables first in case of error!

    Adam.
    Or you can just choose SQL View from the View drop down and use the above query.
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  7. #7

    Thread Starter
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015
    Thank you one and all. I was misled into believing it had to be coded in VB, by an instructor, no less~!

  8. #8
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Originally posted by DUNSEL
    Thank you one and all. I was misled into believing it had to be coded in VB, by an instructor, no less~!
    The instructor is not wrong necessarily. This could be done from vb if it is part of a bigger routine. But if it is a one time thing then you would just use access.
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  9. #9

    Thread Starter
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015
    Well, not a one time thing, in the sense that I want all changes in the field subtracted, to be reflected in the one subtracted from. I'm new to programming ( student at Chubb, the IT school that sounds like a fat farm) and I was sure there was a way to do it in Access alone, with the simple equation you gentlemen posted, but I was told it was not so.
    Last edited by DUNSEL; Nov 6th, 2002 at 11:59 AM.

  10. #10

    Thread Starter
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015
    One last question on this; If I'm using a data environment, can I create the query in the SQL builder of the command, and if so, is the SQL syntax different? I tried and it rejected it.

  11. #11
    Member
    Join Date
    Oct 2002
    Posts
    50
    The following code will run the stored update query held in the database from within vb. (i've never used the data environment)

    Dim db As Database
    Set db = OpenDatabase("c:\FullDatabasePath.mdb")
    db.Execute ("nameOfStoredUpdateQueryInTheDatabase")
    db.close

Posting Permissions

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



Click Here to Expand Forum to Full Width