Results 1 to 7 of 7
  1. #1
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114

    CboBox row source - How to construct a list from a constant and a variable?

    I want to dynamically construct a combox row source to designate a filter for a report. So it will be unbound, and I envision the row source type to be "list". I want the first member of the list to be a string, like "all" or "master." The remaining list items should be ascending numeric characters, starting with "1" and ending with "n", where n is drawn from a control bound to a field. (N represents the number of cameras used on a particular shoot. The idea is to build in flexibility to generate a particular camera's shotlist or the master shotlist, where the total number of cameras will vary by shoot.)

    What's the proper way to construct that sort of row source?

    Thanks.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    The point of the combox IS to bind it to a list you want to use. A query that reads from a table..in your case

    tCameras
    -----------
    [shoot]
    [Camera]

    the query will pull the list of cameras for your particular shoot. Keep them in the list. This query can also filter via another combo (cboShoot)
    Use tables and queries.

  3. #3
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Thx. Not following, but guess I wasn't clear. Isn't the .value of cboMyControl (or lstMyControl) the text that is displayed? All I want is programmatic access to that value. But the possible choices are to be constructed from a mixture of a literal string and a bunch of calculated figures (derived from a single value - the total number of cameras). Guess I can write a UDF.

    So let me rephrase: Will this work

    cboMyBox.rowsource = MyUDF(ShootsID) where .rowsourcetype has been defined in design as "Value List" and the UDF resolves to a literal string, properly delineated for a cbo or lstbx value list?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Use looping structure and AddItem method http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Isn't the .value of cboMyControl (or lstMyControl) the text that is displayed?
    Not necessarily. It depends on what the Bound Column property is set to.

    If you have a table/query with one column in the query, then yes, you are correct.
    If you have a table/query that has 3 columns in the query, the bound column property can be set to column 1, 2 or 3. Usually, the bound column is 1, but I have seen where someone set the bound column to a different number.

    If you are setting the Row Source Type property to "Value List" and there is only one column, then yes, the value of the combo box/list box is the value displayed.

    What is the max number of cameras that could be on a shoot? Don't remember the total characters that can be put in a value list... (32,750)?

  6. #6
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    June, I forgot about that method. That's probably the way I'll go. Thank you! "Native" functionality much preferred to writing my own

    Steve, thanks for the explanation. The help file for the .boundcolumn property says pretty much what you say:
    http://msdn.microsoft.com/en-us/libr...ice.14%29.aspx

    However, the first sentence of the help on the .value property (which I realize is the default property for the control),
    http://msdn.microsoft.com/en-us/libr...ice.14%29.aspx
    says: "The Value property is set to the text in the text box portion of the control." There's then some distinction made vs. the .text property, but nothing about binding.

    BTW, if there was an issue caused by the .bound property, could I not use the .column(n) property to get the value I'd want?

    At my (hobbiest) stage, this notion of binding is confusing. I thought that binding means that a change in a control's value will change an underlying table field represented in the controlsource. Since I don't have a controlsource in this case, I was thinking of it as unbound. Guess I gotta dig deeper into understanding the binding concept, since it appears to apply even to the rowsource. I think this is what Ranman was trying to tell me, doh!

    No worries about the number of cameras. I guess Steve you're implying that that UDF approach would work. June's suggestion is still more sensible I think.

    BTW, FWIW, there is a way to construct a query to do what I want for the rowsource. (I'd done it months ago in a test and forgot.) It will show only those cameras in the current recordset though. It combines a select distinct with the fixed text item(s) through a UNION operator.

    Anyway, thank you to all. -Ron

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Confusing BoundColumn with ControlSource.

    ControlSource binds to field (or in an UNBOUND textbox this can be an expression).

    BoundColumn determines which column value is saved.

    A combobox or listbox can have multiple columns and the BoundColumn determines which column sets the control's value, even if the ControlSource is not set (an UNBOUND control).
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 05-06-2014, 09:14 PM
  2. Row source value list filter
    By Ruegen in forum Programming
    Replies: 1
    Last Post: 01-27-2014, 10:19 PM
  3. Declaring a Variable Constant (Sort Of)
    By emmahope206 in forum Programming
    Replies: 1
    Last Post: 02-27-2013, 11:15 AM
  4. Replies: 1
    Last Post: 03-01-2011, 03:04 PM
  5. Replies: 11
    Last Post: 04-16-2010, 10:57 AM

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