Results 1 to 4 of 4
  1. #1
    wtolentino is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Mar 2009
    Posts
    13

    search/find/select record before delete/update

    i have a lookup form that i called room list and on this form i want to prevent/stop from deleting/updating when the same record is being used from the other tables. let say for example



    Code:
    select count(*) into vCnt
      from tblBuilding tb
    where tb.room_code = [forms].[room_code]
    
    if vCnt > 0 then
      stop
    end if;
    how do i programmatically code it on ms access?

    thanks.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Not sure what you're asking.
    you can prevent records from being deleted from child tables using the relationship rules. No code needed.
    Do not set cascade delete. Then users cannot delete parent records if children exist.

  3. #3
    wtolentino is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Mar 2009
    Posts
    13
    thanks. because it is only a lookup table i do not want to create relationship rules. i only want to prevent the lookup table from deleting/updating the data if the same data is being used in another tables.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You would need to execute the code for every table that the data could be saved in.

    Maybe
    Code:
    select count(*) into vCnt
      from tblBuilding tb
    where tb.room_code = [forms].[room_code]
    
    if vCnt > 0 then
      Exit sub
    end if
    
    select count(*) into vCnt
      from tblRentals tb
    where tb.room_code = [forms].[room_code]
    
    if vCnt > 0 then
      Exit sub
    end if
    .
    .
    .
    (just one way to write the code)

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

Similar Threads

  1. Replies: 8
    Last Post: 08-30-2016, 06:02 PM
  2. Replies: 2
    Last Post: 07-17-2014, 02:07 AM
  3. Delete command to update record
    By angie in forum Forms
    Replies: 6
    Last Post: 12-23-2013, 05:26 PM
  4. Replies: 1
    Last Post: 07-16-2012, 01:57 PM
  5. Replies: 2
    Last Post: 01-24-2012, 02:16 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