Results 1 to 5 of 5
  1. #1
    Oxygen Potassium is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2016
    Posts
    40

    Stop Subform From Loading

    I have a subform that I do not want to load if the main form doesn't load. I'm using the coding below but get an error message saying "Compile error: Statement invalid outside Type block" and points to the line FinishedLoading As Boolean on the main form. I may just be a little bit off or maybe there might be a better method to accomplish this?

    Coding on Main Form:

    Private Sub Form_Load()

    FinishedLoading As Boolean

    Forms![Vendor Reporting Navigation].Visible = False
    Dim pwd As String
    pwd = InputBox("Enter Password?")


    If pwd = "ABC123" Then
    MsgBox "Password Accepted"
    Else
    MsgBox "Incorrect Password"
    DoCmd.Close
    End If

    FinishedLoading = True

    End Sub



    Coding on SubForm:

    Private Sub Form_Close()

    If Not Forms("Maintenance Reports List").FinishedLoading Then
    Exit Sub
    End If

    On Error Resume Next
    DoCmd.RunMacro "Update Due Dates"
    DoCmd.OpenForm "Duplicates for Master Report Tracking 2", acNormal

    End Sub

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Add DIM in front of it.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I don't see what the issue is. If the main form doesn't load, then the subform won't load either. Entering an incorrect password closes the main form, which closes the subform too.
    In any case, putting the check in the subform's On Close makes no sense - in order to close it, it had to be open anyway, no?

    In answer to your original question, you forgot the "Dim" part: Dim FinishedLoading As Boolean

    However, if you wast FinishedLoading to be accessible to other sub, you have to declare it as Public (not Dim), and you have to put the declaration at the top of the form code module, outside of all subs.

    What you might do is have a separate login form which opens first, asks for the password, then opens your main form only if the passwoed is correct.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    You may get some additional ideas from this youtube video by Steve Bishop on UserAccess
    or this one on Login form
    Also, you may get more focused responses if you give readers a brief overview of your issue/opportunity in clear, simple English.

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

Similar Threads

  1. Replies: 11
    Last Post: 06-15-2016, 07:43 AM
  2. #Name? error when loading a subform
    By stardust1979 in forum Forms
    Replies: 2
    Last Post: 12-21-2014, 08:59 PM
  3. Loading different queries in to a subform
    By cowmoogun in forum Programming
    Replies: 1
    Last Post: 11-20-2012, 07:15 PM
  4. Loading subform based on combo box
    By topp in forum Access
    Replies: 1
    Last Post: 10-19-2012, 04:07 PM
  5. Subform loading incorrect data
    By GoVols02 in forum Forms
    Replies: 3
    Last Post: 02-12-2010, 09:53 AM

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