Results 1 to 4 of 4
  1. #1
    hrghauri is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Location
    Ottawa, Ontario, Canada
    Posts
    11

    Why does my form disappear in a split second? VBA

    I have a sub which instantiates a new form, makes it visible. However the new form lasts only for a very brief moment. This is my code:



    Private Sub txtProject_ID Click()
    Dim frmReq as Form
    Set frmReq = New Form_Request
    frmReq.Visible = True
    End Sub
    I tried to set break points on this and found out the form becomes visible when I set its visibility to true. However it disappears as soon as the Sub ends.

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Is New Form_Request the actual name of the Form to be opened; if so it needs quotes around it:

    "New Form_Request"

    Also, I don't see the Form actually being opened.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    hrghauri is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Location
    Ottawa, Ontario, Canada
    Posts
    11
    I was able to solve this by declaring

    Dim frmReq as Form

    above the subroutine.

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    you have created an instance of a form object declared within the function which you then (presumably) assign it a form and make visible.

    When the function ends, so does the form instance so the form disappears. You need to make the declaration public i.e. at the top of the module you put

    Public frmReq as Form

    Note the module should not be a form module otherwise it too will disappear when the form is closed.

    Note also that when assigning these object properties it is important to close them properly (set them to nothing) - otherwise you will create what is called memory leakage which will start to eat up memory and your application will fail at some point.

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

Similar Threads

  1. Replies: 3
    Last Post: 11-03-2015, 11:19 PM
  2. Replies: 10
    Last Post: 10-05-2015, 09:09 AM
  3. Replies: 7
    Last Post: 10-03-2013, 03:10 PM
  4. Fields disappear in Form View
    By CASmith in forum Forms
    Replies: 7
    Last Post: 10-02-2012, 04:54 PM
  5. Replies: 2
    Last Post: 03-13-2009, 08: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