Results 1 to 7 of 7
  1. #1
    peshonzi is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    21

    Question Update data from two tables

    Hello, it's my first post



    I have a problem - I can't build a proper criteria, probably...

    I have two tables.

    The first one is the general, where I store the data, and the second one is the table from which I lookup...

    The [General] table contains:
    -1 [Location]
    -2 [Distance]

    The [Second] table:
    -1 [Location*]
    -2 [Distance*]

    So I lookup a [Location] from [Location*] and I want to creat an update query that will type the [Distance] from [Distance*] by choosing the right Location.

    I will show you what I did:

    -Field- [Distance]
    -Table- [General]
    -UpdateTo- [Second]![Distance*]
    -Criteria- [General]![Location]

    The tables have reletaionship, and the related fields ([Location] and [Location*]) are with same type and options. But there is a mistake, because it does not do it...

    PLEASE HELP

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    What does distance mean when you associate it with a single Location?

    What do your tables represent?

  3. #3
    peshonzi is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    21
    Hi, orange!

    Well, I work in a company that makes concrete. So we send trucks to different [Locations] which are several miles from the factory([Distance]). So I have to type lots of [Location]-s with the proper [Distance]-s to those Locations

    I have created a form by which I fill the [General]-table, using the data from the [Second]-table. So, I want to create a query, that types the miles when I input the location!

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    So the distance is the distance from the Factory to the Site Location.

    How do you determine the Distance?
    What about other factors, such as Amount of Concrete; Type of Concrete; CurrentCost of Concrete; Customer; etc

    There are free data models at http://www.databaseanswers.org/data_...ucts/index.htm

  5. #5
    peshonzi is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    21
    Look, I've already done the rest of it.

    The only problem is - HOW TO CREATE AN UPDATE QUERY, which is going to input the kilometers, by reading the location I've selected in [General], and using the same location in [Second] to find out the kilometers.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Try this code as your base. If you are getting a value from a selection on a form, you'll have to adjust accordingly.

    UPDATE GENERAL INNER JOIN SECOND ON
    General.Location = Second.Location
    SET General.Distance = Second.Distance;
    EDIT:
    To remove notifications, if that is an issue, you can set up an action query using

    db.execute sqlString,dbFailOnError

    where sqlString is a variable whose value is the SQL of the Update query presented previously.

    Dim sqlString as string
    sqlString = "UPDATE GENERAL INNER JOIN SECOND ON " _
    & "General.Location = Second.Location " _
    & " SET General.Distance = Second.Distance;"
    db.execute sqlString,dbFailOnError
    Last edited by orange; 07-04-2011 at 05:33 AM. Reason: private message

  7. #7
    peshonzi is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    21
    thanks a lot

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

Similar Threads

  1. Replies: 30
    Last Post: 06-26-2011, 10:47 PM
  2. Update 2 tables with one Update Query
    By Douglasrac in forum Queries
    Replies: 4
    Last Post: 04-14-2011, 08:33 AM
  3. Update Query that uses fields from other tables?
    By DarrenReeder in forum Queries
    Replies: 1
    Last Post: 12-06-2010, 10:47 AM
  4. update tables via forms
    By jazoo in forum Forms
    Replies: 0
    Last Post: 09-16-2008, 05:54 AM
  5. Update Tables
    By lschlitt in forum Programming
    Replies: 2
    Last Post: 05-28-2006, 02:11 PM

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