Results 1 to 2 of 2
  1. #1
    FL0XN0X is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Belgium
    Posts
    84

    Refering to Id in Subform and use that Id in Query

    Dear,

    I have got a main form (Main) and a subform (Subform). Subform is showing all records from table Holiday in a Continuous Form. The Id of each record is set to Visible=No. Next to each record, I want to add a command button which deletes the corresponding record when pressed using the execution of a Query in the On click event.

    The query looks like:

    DELETE *
    FROM [Holiday]


    WHERE Id=Forms![Main].[Subform].Forms![Id];

    But a pop-up keeps appearing indicating that it cannot found the referenced Id ....

    Can anyone tell me how the Where statement must be corrected?

    PS: when manually providing the pop-up msg with an id, the corresponding record is deleted correctly, so the only thing that is wrong is the Where statement (I think)
    Last edited by FL0XN0X; 03-15-2018 at 02:55 PM. Reason: solved

  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Your first post says solved in the edit line but the question was left for a response so...

    The subform syntax is wrong

    Code:
    DELETE *
    FROM Holiday
    WHERE Id=Forms!Main.Subform.Form.Id;
    Note changes from bang to dot, removal of unnecessary [] and use of Form to select the subform control

    This link may also be useful for future refe: http://allenbrowne.com/casu-04.html
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

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

Similar Threads

  1. refering to a field on a form
    By StuartR in forum Forms
    Replies: 2
    Last Post: 02-20-2018, 05:57 AM
  2. Replies: 8
    Last Post: 06-19-2015, 02:19 AM
  3. Replies: 1
    Last Post: 06-21-2012, 09:38 AM
  4. Replies: 1
    Last Post: 05-23-2012, 11:45 AM
  5. Replies: 3
    Last Post: 06-03-2009, 07:15 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