Results 1 to 2 of 2
  1. #1
    KBNETGUY is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    26

    Logic to display a button or not

    I have a sub-form on a form page. There is a button on the main form that when pressed executes an append query to insert records into the sub-form using the parent ID of the current parent record. In the event there is already data populated in the sub-form I would like to prohibit users from A. either seeing the button or B. message box that indicates sub-form data has already been entered. The purpose is if someone accidentally presses the button. Here is the current Script for running the procedure.

    FYI - the sub-form is based off of an existing form. Is there a way to simply ide



    Code:
    Private Sub InsertCustDisc_Click()
    On Error GoTo Err_InsertCustDisc_Click
    
    
        Dim stDocName As String
    
    
        stDocName = "CC_CustDiscount_APPEND"
        DoCmd.OpenQuery stDocName, acNormal, acEdit
    
    
    Exit_InsertCustDisc_Click:
        Exit Sub
    
    
    Err_InsertCustDisc_Click:
        MsgBox Err.Description
        Resume Exit_InsertCustDisc_Click
        
    End Sub

  2. #2
    Gicu's Avatar
    Gicu is online now VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    To do the first (hiding the button) you need to add this to the OnCurrent event of the main form:

    If Me.subformcontrolname.form.recordset.recordcount>0 then Me.InsertCustDisc.visible =False (or to disable it use Me.InsertCustDisc.enabled =False

    For the second option (adding a warning and exiting) you can try:

    Private Sub InsertCustDisc_Click()
    On Error GoTo Err_InsertCustDisc_Click


    Dim stDocName As String

    If Me.subformcontrolname.form.recordset.recordcount>0 then

    msgbox "Your message here"

    exit sub

    end if



    stDocName = "CC_CustDiscount_APPEND"
    DoCmd.OpenQuery stDocName, acNormal, acEdit


    Exit_InsertCustDisc_Click:
    Exit Sub


    Err_InsertCustDisc_Click:
    MsgBox Err.Description
    Resume Exit_InsertCustDisc_Click

    End Sub

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

Similar Threads

  1. Replies: 2
    Last Post: 12-16-2014, 08:36 AM
  2. Seeking a User Friendly enter Button Logic
    By justphilip2003 in forum Programming
    Replies: 4
    Last Post: 05-10-2013, 12:12 PM
  3. Display random record with button
    By shredsec in forum Forms
    Replies: 3
    Last Post: 01-01-2013, 02:27 AM
  4. Display Average as a radio button
    By boo in forum Forms
    Replies: 4
    Last Post: 02-01-2012, 12:28 PM
  5. Replies: 2
    Last Post: 02-01-2012, 07:35 AM

Tags for this Thread

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