Results 1 to 4 of 4
  1. #1
    equestrian is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2015
    Posts
    15

    In a form how to check the value in a related table before deleting a field

    I have a form frmEntryTabbed (allows the user to enter fields in tblEntry) and a subform frmEntry_subform (allows the user to enter fields in tblShowClassEntry). I have a button on frmEntryTabbed that deletes the current record in tblEntry.
    Code:
     
    Private Sub cboDeleteEntry_Click()
    On Error GoTo Err_cboDeleteEntry_Click
    

    DoCmd.RunCommand acCmdSelectRecord DoCmd.RunCommand acCmdDeleteRecord Exit_cboDeleteEntry_Click: Exit Sub Err_cboDeleteEntry_Click: MsgBox Err.Description Resume Exit_cboDeleteEntry_Click End Sub
    Before deleting the record I would like to check the value in a related table. The basic layout of the tables is as follows:

    tblEntry
    EntryNum_pk
    RiderNum_fk
    HorseNum_fk

    tblShowClassEntry
    EntryNum_fk
    PlacingNum_fk

    tblPlacement
    PlacementNum_pk
    PlacementNumerical
    Placement

    For each entry there may be multiple classes entered. If any of the classes entered has a value in PlacinNum_fk not equal to 7, I want to display a message and not allow the record to be deleted.

    Any help will be appreciated. Thank you

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Maybe do a DLookup()? Might want to use the BeforeDelete event to do this validation.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    equestrian is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2015
    Posts
    15
    Thank you for the help. I could not get the DLookup to work. It returns the first value and there could be multiple classes entered. The first may or may not be equal to 7. It did give me another idea. I put 2 text boxes with visible marked as no on the form. One has the minimum value of PlacingNum_fk and the other has the maximum value of PlacingNum_fk. if either of these are not equal to 7, I display a message and do not delete the record.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Then the DLookup did not have specific enough search criteria.

    Glad you found a solution.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 08-27-2014, 04:16 PM
  2. Replies: 3
    Last Post: 04-09-2014, 12:48 PM
  3. Replies: 4
    Last Post: 04-26-2012, 11:04 AM
  4. Deleting record and related records
    By TedT in forum Access
    Replies: 2
    Last Post: 10-25-2011, 04:26 PM
  5. Replies: 11
    Last Post: 12-14-2010, 01:25 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