Results 1 to 7 of 7
  1. #1
    lupis is offline Novice
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    23

    Catching record id in a form

    I have a INSERT INTO query to upload and download a table between a local access table and a online sql server table and a UPDATE query to do the same. I have this connected to a button in a form.



    My issue is instead of doing the INSERT INTO and UPDATE queries for all the records in the table I would like to have a WHERE condition for my current record ID in my form (the ID being the primary key), so only the one record in a form is altered and passed between the local access table and the online sql server table.

    So how do I catch the record ID of one row in the form and pass it as an arguement for the WHERE condition in my INSERT INTO and UPDATE queries. I want to do this via a button in the form.

    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Presuming these are saved queries, you can add a criteria on that field of:

    Forms!FormName.ControlName

    replacing with the appropriate form and control names. As long as the form is open, your action queries should be restricted to the current record.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    lupis is offline Novice
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    23
    Hi Paul,

    Thanks for your reply. I used the following WHERE condition on my query, WHERE (((Contacts.ID)=[Forms]![Contact List].[cmdExportRecord]));
    But after inserting a new row in my form and that row is marked and clicking on the button with the control name cmdExportRecord I get the reply that I am appending 0 rows!
    What have i missed? Also in the macro for that button, should the data mode for the action "open query" set to be add or edit if i have a INSERT INTO clause on that query?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    You have the button in the criteria. You want the control that has the key field there (looks like "ID"). You're telling the query where to find the value to restrict records on.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    lupis is offline Novice
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    23
    Thanks Paul... How do I put a "SOLVED" tag on this post by the way

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    lupis is offline Novice
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    23
    Could you also help me on the following thread please: https://www.accessforums.net/import-...bles-5726.html

    I am trying to INSERT INTO and UPDATE to two local tables with a FK relation between them to be imported/exported or updated to a online SQL server table. I have a form in access that uses both these local tables, and I want the local changes and updates to be reflected on to the online SQL server tables and vice versa.

    thanks

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

Similar Threads

  1. Replies: 0
    Last Post: 05-04-2010, 06:39 AM
  2. Replies: 1
    Last Post: 04-13-2010, 12:18 PM
  3. Replies: 3
    Last Post: 06-27-2009, 03:53 PM
  4. Replies: 9
    Last Post: 03-24-2009, 09:19 PM
  5. Replies: 0
    Last Post: 11-10-2008, 12:32 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