Results 1 to 3 of 3
  1. #1
    Mitch_Aus is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Posts
    1

    docmd.runsql update

    Hi Guys;


    I have a database with 2 tables. The first table called "shots" has a field "shotstodate" that is updated by an import from a master database. i open the second the second table by a button on a menu, when i click the open button i would like all the data in the table "shots", with the field called "shotstodate" to be automatically updated to the second table called "diemaster" into the field "shotstodate".

    I cant get my head around it, i know i need to use the DoCmd.RunSQL update but what do i do next, can someone please help me. I have goggled by i still can't work it out.

    I don't want to use a query, i would just lie the entire field updated every time i open the form.

    Thanks

    kevin

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Hi Kevin,

    If I understand correctly, you want to take *ALL* of the records in the table "Shots" for one field "shotstodate" and append them into a table named "diemaster" in a field named "shotstodate".

    To do this, a query would look like this:

    INSERT INTO diemaster ( shotstodate )
    SELECT shots.shotstodate
    FROM shots;


    Using code, you can do it using one line using an append query:


    Code:
    Public Sub Shots()
       CurrentDb.Execute "INSERT INTO diemaster ( shotstodate ) SELECT shots.shotstodate FROM shots;", dbFailOnError
    End Sub

  3. #3
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    I dont think an insert-into would work here because, as I understand it, he is looking to update the number of shots taken per primary key. so if until yesterday, key 123 took 50 shots, and today took 3 more, the shotstodate should show 53 for key 123. what you would want is an update query:

    UPDATE diemaster
    SET shotstodate = shots.shotstodate
    WHERE shotstodate.PrimaryKey = shots.PrimaryKey

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

Similar Threads

  1. DoCmd.OpenQuery with Parameters?
    By mwhcrew in forum Queries
    Replies: 5
    Last Post: 10-10-2014, 01:49 AM
  2. DoCmd OpenReport ... where condition with a Like
    By Grooz13 in forum Programming
    Replies: 4
    Last Post: 08-31-2010, 09:04 AM
  3. Problem with DoCmd.RunSQL
    By Peter01 in forum Programming
    Replies: 2
    Last Post: 09-10-2009, 07:11 PM
  4. docmd.runsql not working
    By Rameez in forum Programming
    Replies: 3
    Last Post: 08-07-2009, 10:07 AM
  5. DoCmd.SendObject Help
    By bgreer5050 in forum Programming
    Replies: 0
    Last Post: 01-12-2007, 06:27 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