Results 1 to 3 of 3
  1. #1
    Sa'El is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Sep 2011
    Posts
    40

    Error Handling: How to Skip an expected Error

    Hi All,

    I have 2 main forms with the same subforms (the main forms specify context of the subforms, and are mutually exclusive). Up until now the fact I had 2 main forms weren't an issue since any programming I have done was within the same form, i.e. using "Me.____".

    I now have a situation where I am in a 2nd level subform that needs to change the properties of another subform so that I no longer can use "Me.____". I got the syntax to call the subform correctly, but the inherent issue is that the code will only work on the active form, and there are 2 possible forms that the code would work on.

    Logically, I want to call the code to account for both scenarios, and for whichever the scenario the code isn't applicable (the form that is not open), then Access would simply skip it. So yes, an error is expected, but I don't want to ignore it. This is the relevant part of the code:

    Private Sub Form_Load()
    If Me.AD_cmbContactedNP = "Yes" Then
    Me.AD_cmbWhoContNP.Enabled = True
    Me.AD_NoNPContactExplain.Enabled = False
    Forms![4) ED Visit Current Readmission]![SubMain3 Current Readmission].Form![Sub6b_IntervenOpps].Visible = True
    On Error Resume Next
    Forms![4) ED Visit Current Readmission]![SubMain3 Current Readmission].Form![lblNPContacted].Visible = True
    On Error Resume Next
    Forms![4) Direct Readmission]![SubMain3 Current Readmission].Form![Sub6b_IntervenOpps].Visible = True
    On Error Resume Next
    Forms![4) Direct Current Readmission]![SubMain3 Current Readmission].Form![lblNPContacted].Visible = True
    On Error Resume Next

    The Red is Main Form 1, and the Blue is Main form 2. I was hoping that "On Error Resume Next" would work, but I have an error based on the order of the Code. With the Red Form being first, if I open the Red form I get no errors on loading even though the Blue form isn't opened (remember the Red and Blue are mutually exclusive). If I open the Blue form, I get an error on the code of the first Red line.

    So all I want to do is be able to skip/bypass the error. Any help would be appreciated, thanks.

  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,930
    You have 2 main forms but each uses the same subform objects?

    You have code in a subsubform that references a subform container and a label to control visibility?

    Only one of the main forms will be open at a time? You can do a test for whether or not a main form is open. Try:

    If CurrentProject.AllForms("[4)ED Visit Current\ Readmission]").IsLoaded Then
    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
    Sa'El is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Sep 2011
    Posts
    40
    That worked June! (had to adjust the syntax a little by removing the brackets).

    You continue to be my hero! Take care.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-06-2015, 12:06 PM
  2. Error handling of table update error?
    By panoss in forum Forms
    Replies: 5
    Last Post: 10-31-2014, 02:06 PM
  3. Error Handling Question - On Error Goto
    By redbull in forum Programming
    Replies: 7
    Last Post: 12-06-2012, 07:54 AM
  4. Replies: 3
    Last Post: 09-05-2012, 10:23 AM
  5. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 PM

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