+ Reply to Thread
Results 1 to 12 of 12

creating a dropdown dynamically in multiple rows & assiging values to it from database

Hybrid View

  1. #1
    Registered User
    Join Date
    11-27-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007
    Posts
    35

    creating a dropdown dynamically in multiple rows & assiging values to it from database

    Worksheet.DropDowns.Add(Worksheet.Range(Erow, Erow).Left, Worksheet.Range(Erow, Erow).Top - 1, Worksheet.Range(Erow, Erow).Width, Worksheet.Range(Erow, Erow).Height).caption = ""
    i have teh above code from vb.net to create dropdown in excel dynamically

    this is working fine
    the dropdowns are displayed in each row as per the range given
    i am openinng excel from Vb.net

    the issue is each dropdown has differnt name
    i need to populate all the dropdowns created with data from datbase in vba

    as the dropdowns r created dynamically how do i get the names to populate the dropdowns in vba

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

    Re: creating a dropdown dynamically in multiple rows & assiging values to it from database

    Aren't you creating a reference to each dropdown when you create it?

    If you aren't then you should be because you could use that reference to populate the dropdown.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    11-27-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: creating a dropdown dynamically in multiple rows & assiging values to it from database

    i jst have the above code for creating dropdown for the range of rows in a partcialr column
    how do i create a reference in vb.net & access it in vba workbook?

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

    Re: creating a dropdown dynamically in multiple rows & assiging values to it from database

    Why do you need to access it in the workbook?

    Don't you want to populate it when you create it in the VB.Net code?

  5. #5
    Registered User
    Join Date
    11-27-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: creating a dropdown dynamically in multiple rows & assiging values to it from database

    I am opening the Excel sheet Template from vb.net with few records from vb.net ie Exporting data from the application
    when the Excel template gets opened with the data the user needs to just eneter Qty in each row & select a data from the dropdown which is created in each line

    so i think i dont need the reference of dropdown in vb.net once its exported,
    if i am able to populated the dropdown in vba as all the dropdown will have the same data from datatable

    let me know whts the best


    populating the dropdown from vb.net code & then exporting wuld take time , i suppose

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

    Re: creating a dropdown dynamically in multiple rows & assiging values to it from database

    Why would it take time and what exactly would you be exporting?

  7. #7
    Registered User
    Join Date
    11-27-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: creating a dropdown dynamically in multiple rows & assiging values to it from database

    i wuld be exporting the items , ie itenmane , itmid, qty, item desciption ,, etc

    the items can be 50- 100 at a time so it will take say 100 rows of excel sheet & there will be 100 dropdowns
    so is there a way by which i can populate the dropwn when its exported but before opened for user

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

    Re: creating a dropdown dynamically in multiple rows & assiging values to it from database

    Yes, populate it just after you've created it in the VB.Net code.

  9. #9
    Registered User
    Join Date
    11-27-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: creating a dropdown dynamically in multiple rows & assiging values to it from database

    as said by you i tried to populate the dropdown created from code

    below code creates the dropdown for n no of rows

    Worksheet.DropDowns.Add(Worksheet.Range(ExcRow, ExcRow).Left, Worksheet.Range(ExcRow, ExcRow).Top - 1, Worksheet.Range(ExcRow, ExcRow).Width, Worksheet.Range(ExcRow, ExcRow).Height).caption = ""
    but i get tge error as

    Unable to cast COM object of type 'System.__ComObject' to class type 'System.Web.UI.WebControls.DropDownList'. Instances of types that represent COM components cannot be cast
    to types that do not represent COM

  10. #10
    Registered User
    Join Date
    11-27-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: creating a dropdown dynamically in multiple rows & assiging values to it from database

    i feel it little confusing

    i am creating the dropdown for excel dynamically from vb.net code , so the names of the controls are not knwn
    instead of populating it from vb.net code how do i populate each dropdown controls created with data from database
    2) i exported some data to excel with blank dropdown
    when i try to save the exported excle sheet i get error saying that the excel is corrpouted & cannot be saved

    if i remove the code for dropdown i can save it properly

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    In the last code you posted there's nothing to populate a dropdown.

    Also you still don't create a reference to the dropdown when you create it.

    If you had a reference then you could use it when populating the dropdown.

    By the way, dropdowns don't have a caption property.

  12. #12
    Registered User
    Join Date
    11-27-2013
    Location
    Mumbai
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: creating a dropdown dynamically in multiple rows & assiging values to it from database

    my need as explained is

    1) data from database will be exported to excel with X no of items
    when exporting column K needs to have dropdown filled with data from database
    the dropdown shld appear in all the X rows
    so i had created the dropdown using .ADD method from my vb.net code

    2) after exporting the user will select values from the dropdown & save the excel sheet for importing in database

    hope i am clear
    how do i create a reference to dropdown or how fo i get the id or name of each dropdown created so that it can be used in code

+ 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] VBA for creating dropdown list from dynamic multiple values lookup
    By costin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-29-2013, 05:39 PM
  2. Replies: 0
    Last Post: 01-16-2012, 11:37 AM
  3. dynamically selecting the data from database and creating pivot charts
    By udaygs in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-24-2011, 10:17 PM
  4. Replies: 2
    Last Post: 06-14-2010, 03:34 PM
  5. creating pop-up menu from dynamically generated column values
    By bcamp1973 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-12-2007, 01:11 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