+ Reply to Thread
Results 1 to 8 of 8

Remove and create Userform keeping same name - Memory name conflict

  1. #1
    Registered User
    Join Date
    05-11-2020
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    4

    Remove and create Userform keeping same name - Memory name conflict

    Dear all,
    After learning so much from other members, now its time to write my first post in the forum.
    I am creating an Excel file that, on the main page, shows a Userform (Userform1) if a cell of column "F" is clicked and there is data in the same row of column "B".
    This form launches a second Userform (Userform_Test) showing CommandButtons for the user.

    There is a data base sheet gathering the captions to create the CommandButtons for the Userform_Test.
    If there is a change in the data base, the module called Create_Userform_Test removes the current Userform_Test and creates a new one.
    For the new form created, I need to keep its original name as the form is called from Userform1 but and it is expected to be called from other forms.

    The module Create_Userform_Test works fine if Userform_Test does not exist or if Userform_Test has not been used previously since Excel is launched.
    But, once I've used Useform_Test, it seems like it keeps its name in the memory and vba shows an error name conflict (50135) when trying to name the new form.
    Actually, I think that the initial Userform_Test it is not removed because it keeps active or not properly unload.

    This problem is driving me crazy...

    Any idea about it?


    Thanks for your help
    Attached Files Attached Files
    Last edited by aferrer; 06-18-2020 at 04:48 PM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,263

    Re: Remove and create Userform keeping same name - Memory name conflict

    Why are you deleting the form rather than just adjusting its properties/controls at run time? The latter is far easier and not subject to the user's VBProject access security settings.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    05-11-2020
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    4

    Re: Remove and create Userform keeping same name - Memory name conflict

    Rory, the form (Userform_Test) must be updated if there is a change (add new values, delete or change existing ones...) in the data base worksheet.
    My approach was to completely remove the form and create a new one when a change occurs, in that way I avoid keeping track of the kind of change: a new line added, an existing line removed, a modification in an existing line...
    I just get rid of the complete form an create a new one from scratch.

    Following your advice, I've tried to avoid removing the form. However I still need to remove CommandButtons as the buttons have to be updated according to the change in the data base...
    I get an execution time error when I attempt to remove the CommandButtons.

    Please Login or Register  to view this content.
    Find attached Excel sheet.

    Any hint to tackle this issue?
    Thanks!
    Attached Files Attached Files

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,263

    Re: Remove and create Userform keeping same name - Memory name conflict

    If possible, I suggest you only add the commandbuttons at run time so that you don't need to alter the VBComponent itself at all.

  5. #5
    Registered User
    Join Date
    05-11-2020
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    4

    Re: Remove and create Userform keeping same name - Memory name conflict

    I need to update the number of commandbuttons contained in the form based on the data base content.
    For instance, I don't want a commandbutton to appear in the form if the correspondent line is deleted in the data base.
    In the same way, I need to add a new commandbutton if a new line is added to the data base or to modify the caption of a commandbutton if certain line is modified in the data base.

    How could I do this at run time without altering the VBComponent?
    Thanks!

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,263

    Re: Remove and create Userform keeping same name - Memory name conflict

    You add them in the Initialize event and then use a class to handle the clicking of the buttons, since they all do the same thing. Here's a basic example.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    05-11-2020
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    4

    Re: Remove and create Userform keeping same name - Memory name conflict

    Rorya, that worked great!!
    Thank you

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,263

    Re: Remove and create Userform keeping same name - Memory name conflict

    Glad to help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Thrashing VBA Memory Leaks. Memory Loop Problems. Uncleared Memory in .Match Range Object
    By Doc.AElstein in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-10-2017, 05:17 PM
  2. Create Userform to Edit, View, Remove and Find next/ previous data
    By Faridwahidi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-17-2015, 11:00 PM
  3. VBA Userform error: Out of memory
    By JBDC in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2015, 02:39 PM
  4. Opening workbook from userform keeping userform at background..
    By cooldude113322 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-05-2012, 12:14 PM
  5. Replies: 4
    Last Post: 08-02-2006, 11:20 AM
  6. Remove object from memory
    By lexcel in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-01-2006, 10:20 PM
  7. userform memory
    By jnasr00 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-09-2005, 11:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1