+ Reply to Thread
Results 1 to 16 of 16

Module Subs executing Private Subs without prompt by code - Totally Lost

  1. #1
    Registered User
    Join Date
    12-26-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2007
    Posts
    8

    Module Subs executing Private Subs without prompt by code - Totally Lost

    Hello,
    I am new to the forum so I hope that it is alright to ask this question here. If not, I would appreciate if you could direct me to the right place.

    With that said, here is the problem:

    I am building a mini Supply&Sales System. It has sheets governing data entry and sheets containing various databases. Data Entry Sheets (sheets with Tanımlama in their names) have comboboxes with VBA code that extract data from databases, process it, assign it to a dynamic named range and use it as the listfill for the combobox.

    Data Entry Sheets also have buttons that trigger Subs from Module1 in order to extract from, modify and create entries in the databases governed by those data entry sheets.

    However, I have noticed something strange. When I run one of those database modifying subs from Module1, the code will jump to a Combobox governing VBA Private Sub, run that sub and pick up where it left in the Module1 Sub.

    I have no idea why this would happen. I am totally lost. I have built it in a way that prevents this from being a problem for now, but as I continue building the system it will be a major problem in similar tasks. Could somebody please explain to me what's going on and how I can prevent this from happening?

    Illustrative example: Open the attached project. Go to Code. (All Passwords = test). Go to Module1. Find Sub Product_Edit () and step into it (f8). Ignore the first message and you will notice that as you step through the code in the section of code titled "'Transfer data from source to Target" it will switch over to Private Sub Cbo_Product_Tier3_Change() that is part of Products Sheet. Why does this even happen?

    Thanks a lot for all the help you can give!
    Ozan

    PS. I apoligise for the Turkish in the file. It is being designed for non-English speaking users. All non user facing info is in English though.

    PPS. I realise that the code is very inefficient, redundant and amateur. I am sure that there are more elegant solutions. However, these are the solutions that work with my limited VBA knowledge and even more limited time that prevents me from learning more. Why I have decided to undertake such a task with this level of knowledge is also a question I am asking myself.

    PPS. Any help with proper coding is appreciated. Particularly with the interdependant Comboboxes/range extraction from database/dynamic named range creation thing I have going on in the sheet "Ürün Tanımlama".
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    Ozan

    When I run the code it errors here saying it can't find the 'Cbo_Product_Tier1'.
    Please Login or Register  to view this content.
    Is there anything else we need to do to get the code to illustrate the problem?

    Is there a specific sheet that needs to be active for the code to work?
    If posting code please use code tags, see here.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    I don't see that, but get an error on this line:

    Please Login or Register  to view this content.
    What sheet is supposed to be active?

    EDIT: Yeah, what Norie said ...
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    Is it the sheet Ürün Tanımlama that should be active?

    I just found the sub you say is being called - it's empty.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    Managed to get a bit further but now I get a 'Subscript out of range' error here.
    Please Login or Register  to view this content.
    If I change Sheets("Ürün Tanımlama") to the codename Sheet11 the code works but no Product_ID is found.

  6. #6
    Registered User
    Join Date
    12-26-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    Hi,
    Yes Sheet (Ürün Tanımlama) should be active.
    Perhaps you are getting the subscript out of range error due to the fact there are "ı"s and "ü"s in the sheet name and the code? I don't get that error. The code I sent you actually works but makes this crazy detour to private function.

    Changing the sheet name would probably mess up the whole code though.
    I would love to go over it and share my screen via skype if you feel up to it.

    Ozan

    Edit. Cbo_Product_Tier1 is the topmost combo box on the sheet Ürün tanımlama. The ones below are Tier2 and Tier 3 in order.
    Last edited by Ozan Ertem; 12-26-2012 at 03:46 PM.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    Ozan

    The 'crazy detour' is to a sub that does nothing.

    It could be happening because something in the code for Product_Edit is changing the source of the combobox.

    As for the sheet name, I'm not sure what's happening but in the code you have the name with a y in it where there should be an i.

    I didn't change the sheet name, I just changed how the code so it referred to it using the code name.

  8. #8
    Registered User
    Join Date
    12-26-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    Yes it is empty. I would have liked to fill it but because it makes this unintended call to the sub I couldn't.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    How is the combobox populated?

    If it's from a range does Product_Edit change the range in anyway.

  10. #10
    Registered User
    Join Date
    12-26-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    Hi,
    The combobox Cbo_Product_Tier3 is populated from the dynamic named range Product_Tier3 via the Cbo_Product_Tier3_DropButtonClick () private sub in sheet(ürün tanımlama).

    The code in sub Product_Edit does not have any reference to that range which resides in Sheet(Temp_Sheet1). The last line executed before the jump to the empty priva sub is:
    Please Login or Register  to view this content.
    Have you been able to recreate the detour I mentioned?

    EDIT: Would it help if I created an English character version of the file?

    EDIT2: I will click one thousand of your stars if we can figure this out :D
    Last edited by Ozan Ertem; 12-26-2012 at 04:04 PM.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    Yes, but not properly - I had to skip parts of the code, set values (Product_ID) etc.

    Is there anything I need to enter on the worksheet or select from the comboboxes to have the code run without me having to intervene.

  12. #12
    Registered User
    Join Date
    12-26-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    OK, I see your problem now. Download this new file I provided below. I got rid of Turkish characters in Sheet Names and relevant parts of code. All subs that start with Product are working fine.

    If you step into the Product_Edit sub wit the current data set I have provided pre-selected, you should be seeing the problem.
    Attached Files Attached Files

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    I was able to recreate the problem but I don't see why it's happening.

    What's the actual problem with the harmless 'detour'?

  14. #14
    Registered User
    Join Date
    12-26-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    I would actually like to post code into the detour. For Example, I want the list to repopulate once I click on the combobox or make a change on the combobox as well.

    Therefore, try posting the exact same code into Cbo_Product_Tier3_Change () and Cbo_Product_Tier3_Click () as the Code from Cbo_Product_Tier3_Dropdown. Then I get so many errors that I don't know even where to begin debugging from :-D

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    Why do you want to repeat the code?

  16. #16
    Registered User
    Join Date
    12-26-2012
    Location
    Türkiye
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Module Subs executing Private Subs without prompt by code - Totally Lost

    Because if the user clicks on the white space of the combobox to type, instead of clicking on the drop button, then the list does not repopulate. I may also need to execute similar code in future additions that require me to take action when the combobox value changes.

    For instance try selecting "Kahvaltilik" from the top box and then typing "bal" in the middle box. Press enter. Nothing happens. For this, I need to repopulate the list upon change and click as well. At least, that's how I think it works. Do let me know if I'm missing something here.
    Last edited by Ozan Ertem; 12-26-2012 at 05:38 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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