+ Reply to Thread
Results 1 to 18 of 18

New to Forms-Display a blank combobox but have one column in it restricted to a combobox?

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    New to Forms-Display a blank combobox but have one column in it restricted to a combobox?

    Hello all,

    I have another pressing user form question.

    I don't know if this even possible so I will describe what I want and you can tell me if its wishful thinking.

    I want to show the end user a blank combo box (say 1-2 rows and 3 columns wide. The 1st column will be for an invoice primary key and be hidden. The 2nd column will be for an invoice number and the third column will be for an amount). When the end user selects the 2nd column (i.e. 1st visible column), they will receive a dropdown containing the invoice numbers for that client. in otherwords a combobox within a column of a combobox. Is this even possible?

    If not, how should I go about achieving a similar result?
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    Not using comboboxes, no. You could probably piece together a control from labels and comboboboxes and have it look like a combobox - have a look on Andy Popes page, he creates a combobox from labels to use as a colour picker; tbh I'd say it's not worth the effort - but going on some of your other posts.....

    You might have an easier time using something like a listview or flexgrid as a base http://www.vbforums.com/showthread.p...ide-a-Listview, but I'm not at all sure on the availability of these types of controls on most machines - they were for the most part developed for VB6 which is as dead as a dodo.

    If it were me, I'd look at your approach and see if you can find another way - I can't really suggest anything since I've no idea what you're doing - that and I find it abhorrent that multiple invoices would share an "Invoice Primary Key"

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    Quote Originally Posted by Kyle123 View Post
    tbh I'd say it's not worth the effort - but going on some of your other posts.....
    [Wince] You didn't need to say that... XD


    Quote Originally Posted by Kyle123 View Post
    You might have an easier time using something like a listview or flexgrid as a base http://www.vbforums.com/showthread.p...ide-a-Listview, but I'm not at all sure on the availability of these types of controls on most machines
    It looks interesting but I can't figure out how to get the downloaded attachments working in VBA. :S And I don't like the idea of involving external systems for something like this (I would rather change my approach).


    Quote Originally Posted by Kyle123 View Post
    If it were me, I'd look at your approach and see if you can find another way - I can't really suggest anything since I've no idea what you're doing
    Well it's a form for an accounts department for matching receipt payments against outstanding invoices.

    The first page of the multipage has already collected the receipt date, the client name and the total amount paid. This data is validated and the primary key for the client name is matched and used to connect to a database and collect an array of all the unpaid invoices for this customer.

    What I was describing in the OP is what I hoped to have on the 2nd page of the multiform. The end user needs to be able to assign amounts against one or more of the outstanding invoices (ideally the invoices would be chosen from a listbox or combobox). When the total of the amount/s assigned against the invoice/s equal the total paid (from the first page of the multiform), then the end user presses a button to "save" the completed breakup (i.e. writes the amounts paid against each outstanding invoice in the database along with the payment date etc).

    Which is why I thought of a dropdown list inside an empty combobox (I was thinking of the VBA equivalent of what can be done in Excel with a table and a dropdown box). It seems I will need an alternative approach.



    Quote Originally Posted by Kyle123 View Post
    I find it abhorrent that multiple invoices would share an "Invoice Primary Key"
    So do I. And they're not.
    I do have a little bit of database background. I am reluctant to rely merely on an invoice number/code (which is assigned by the end users) as the primary key. So instead each new invoice created silently generates a unique primary key for that invoice. In the combobox I envisioned the end user would only select the invoices by their invoice numbers. But in the background, I am actually linking to the primary key for that invoice, not the invoice number.

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

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    You want the user to pick an invoice no from a blank combobox then have all the clients invoices displayed?

    Why aren't they picking the client from a non-blank combobox?

    As for a combobox within a combobox, I can't see that happening, why not have a separate listbox that lists the invoice numbers based on what the user has selected in the combobox?
    If posting code please use code tags, see here.

  5. #5
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    Hi Norie

    Quote Originally Posted by Norie View Post
    You want the user to pick an invoice no from a blank combobox then have all the clients invoices displayed?
    Almost. What I had in mind was this: A blank combo box (2 visible columns, say 1 row) would be displayed on the 2nd page of a multiform. If the user clicks in the first visible column in the combobox, a dropdown of current outstanding invoices would appear (similar to a dropdown list in Excel when you click in the entry cell). The user will then select an invoice. User tabs to the 2nd visible column and enters a currency. Upon selecting this cell, the combobox automatically expands to add another row so that the user can then assign a 2nd invoice and amount. And so on. (Yes the last bits weren't described in the OP, I was going to break it down into individual problems).


    Quote Originally Posted by Norie View Post
    Why aren't they picking the client from a non-blank combobox?
    They will be. The code for picking the client is on the first page of the multiform and this will be a combobox with a list of current debtors (code is working for this).


    Quote Originally Posted by Norie View Post
    As for a combobox within a combobox, I can't see that happening, why not have a separate listbox that lists the invoice numbers based on what the user has selected in the combobox?
    Well I could but then how would the end user breakup the total against individual invoices?

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    Just use a combobox with a textbox alongside and add as many as you need dynamically underneath - you'll need classes to handle the events, but it should be fairly trivial.

    BTW what db are you using?

  7. #7
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    Quote Originally Posted by Kyle123 View Post
    Just use a combobox with a textbox alongside and add as many as you need dynamically underneath - you'll need classes to handle the events, but it should be fairly trivial.
    A combobox with a textbox alongside = Check.

    Add as many textboxes as I need dynamically underneath = I'm not sure I will be able to work that out. (I am new to forms as per thread title)

    Classes to handle events but should be fairly trivial = Help!

  8. #8
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    I could build a combobox on 2nd page of multiform change. The combobox will display ALL of the outstanding invoices for that client (rather than select by a dropdown list). This will look very messy and, in some cases, could end up going off the edge of the multiform due to the size of the combobox after populated

    And it isn't what I was after (which was an auto expanding combobox with a dropdown in the first visible column).

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    I'll put you a workbook together when I get to work, I've got a mac at home and no excel...

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    Right, this is a proof of concept so it's rough and ready and not fit for production but it demonstrates the principles involved. If you haven't used classes before, try not to be put off - you like making things difficult so consider this being thrown in at the deep end

    I'm happy to explain how it works, but I think you'd be better off stepping through it and seeing how much of it you can follow on your own and then post back with specific questions. There is a huge amount going on and potentially some difficult concepts for a beginner; here's a brief overview:

    The object is made up of two classes that create a new control:

    The parent class - cDropdown: there is only one instance of this class per "fancy dropdown"
    The child class - cDropDownRow: there is a separate instance of each of these for every row in the "fancy dropdown"

    cDropdown handles the initial set up of the control and holds a reference to all the children (cDropdownRows) in a collection - it deals with attaching the control to the form, raising events for the form and handling the button that opens and closes the form.

    cDropdownrow handles the creation of each row, it adds the controls to each row and responds to the events in the controls of each row, when something changes (in this case the textbox value) it lets the parent know, which in turn raises an event and lets the form know.

    See how far you get with it and see if it what you're after
    Attached Files Attached Files

  11. #11
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    Thanks Kyle. It wasn't quite what I had in mind - however this may work out better

    I will play round with it and get back to you in a week or so.

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    How'd you get on with this?

  13. #13
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    This is great Kyle! +1

    I have a few questions if you don't mind.
    1. I want the "fancy dropdown" to be visible on the form initialize. And do away with Command Button 1 altogether. Is this possible? (Don't laugh - I've never written a class in my life!)
    2. How do I return .value of the txtbox from the last row in the "fancy dropdown"? (I plan to use this to check that the txtbox is greater than 0 before allowing the user to add new row)
    3. Last but most important - I need a way of retreiving the data entered by the user. How do I create an array of the values of all the combo boxes & text boxes currently in the "fancy dropdown")
    Last edited by mc84excel; 07-08-2013 at 12:21 AM. Reason: update to latest questions

  14. #14
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    Ok, so in answer to your questions:

    1. I'm not 100% clear on what you mean by this, do you mean that you'd want it as a "Fancy Listbox" rather than a "Fancy Dropdown"? If so then yes, this is a trivial change.

    2. You would get the last entry added to the cRows collection and read it's tbValue property, I've also added a property to return this in the workbook, both work in the same way though:
    Private Sub CommandButton2_Click()
        Dim noRows As Long
        noRows = oListView.cRows.Count
        MsgBox oListView.cRows(noRows).tbValue
    End Sub
    3. You loop through the public collection of cRows - I'm not sure that you'd need to add them to an array separately, but it's up to you:
    Private Sub CommandButton3_Click()
        Dim oRow As cDropDownRow
        For Each oRow In oListView.cRows
            Me.TextBox2.value = Me.TextBox2.value & "CbValue: " & oRow.cbValue & vbTab
            Me.TextBox2.value = Me.TextBox2.value & "TbValue: " & oRow.tbValue & vbCr
        Next oRow
    End Sub
    See the attached with all the above
    Attached Files Attached Files

  15. #15
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    Thanks Kyle

    It's coming together nicely. I have uploaded where I'm up to. I want to alter the Comboboxes so they allow for the input of a 2D array but only the 2nd array data visible (width = "0;" ) however I can't work out how to do this in the Class modules.
    Attached Files Attached Files
    Last edited by mc84excel; 07-08-2013 at 11:22 PM.

  16. #16
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    No problem, can you follow how it works?

    You just need to adjust the properties of the combo-box when it is created:

        With o_cb
            .Top = lRowTop
            .Left = L_ROW_LEFT
            .Width = L_CB_WIDTH
            .Height = L_ROW_HEIGHT
            .ColumnCount = 2 '2 Columns
            .ColumnWidths = "0pt" 'Hide the first one
        End With
    Your other problem then is that your label has a "$" prefix which is throwing an error since you can't subtract from a string.

    You also need to call oListView.Dispose in your submit routine (or anywhere you close the form) to prevent memory leaks

    When I changed both, everything worked as expected
    Last edited by Kyle123; 07-09-2013 at 03:41 AM.

  17. #17
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    Thanks again Kyle.
    • No I can't say that I completely follow how the Class modules work. (Note to self - I must learn these soon).
    • Combo box properties: (Slaps forehead) Of course. I should have thought of trying that! Thanks!
    • $ in Label: I'm only using the $ as a place holder on the form in design mode. (I will be making sure that the final version validates/cleans the curTestAmount before loading the form).
    • Point noted re oListView.dispose

    I think I can probably take it from here so I will mark this as solved. If I do have any further questions, I will reopen the thread and/or PM you.

  18. #18
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: New to Forms-Display a blank combobox but have one column in it restricted to a combob

    Added code to a tool that required it - and it works great!
    Last edited by mc84excel; 07-15-2013 at 07:43 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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