Results 1 to 2 of 2
  1. #1
    skidawgs is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2019
    Posts
    26

    Question Subform and Form_Before Update Event

    Hi,



    Previously, I was having errors when a user would clear or exit out of a form without clicking the “Submit” button, and the record was still be inserted into the Table. In an attempt to combat this, I have included the following code:
    Code:
     Private Sub Form_BeforeUpdate(Cancel As Integer)
     
     If blnGood = False Then
        If (Me!SfrmAddMod2.Form.cboModNum Is Me.ActiveControl) Then‘ This is what I am still searching fo
            …. (text but this doesn’t really matter.. so long as the else doesn’t run)
        Else
            Cancel = True
            Me.Undo
            Cancel = False
        End If
     End If
    So, my problem now is that I need an If statement to check whether a control (cboModNum) on my subform (sfrmAddMod) is getting focus. This is because, when I click on my subform, it causes the Form_BeforeUpdate Event to occur, which then tests my Boolean value used to decide whether a record should be updated, and when its seen that it is false, it deletes all the data from my other input comboboxes. But, I can’t quite figure out the correct If statement to Nest within the statement testing the blnGood value in order to keep my other combobox values from getting deleted when clicking into the subform.

    Any help is greatly appreciated, as I have probably spent way too much time on this already. I’d also be happy to further clarify anything if it helps!

    Thank you!

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    If I interpret your post correctly I think you're looking for a particular syntax for determining if a certain control is the active control. Maybe
    If Screen.ActiveControl = Me!SfrmAddMod2.Form!cboModNum Then

    I'm not a big fan of relying on the ActiveControl property but sometimes it's almost unavoidable, I guess.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 13
    Last Post: 09-10-2015, 03:37 PM
  2. Replies: 2
    Last Post: 04-08-2015, 04:06 PM
  3. Replies: 6
    Last Post: 11-05-2014, 05:27 PM
  4. Replies: 9
    Last Post: 10-21-2014, 12:49 PM
  5. Replies: 7
    Last Post: 05-08-2014, 10:34 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