Add different sequential numbers in combobox in access bases another combobox - ms-access

I'm trying to add a list a sequential numbers in combobox 2 based on the choice made in combobox 1. I have a table that defines how many numbers need to be displayed in combobox2 based on the items in combobox1. What I need to do is that if the number is 3, then it should display 1,2,3 but if the number is 5, it should display 1,2,3,4,5 and so on.
Is this possible ?

Yes, this is possible.
The two easiest ways are probably:
1) Set the RowSourceType to Value List
Then build the string
1;2;3;...;n
in VBA and assign it to the RowSource Property.
2) Create and populate a Number Table (a single INT column, with values 1..n).
Set the RowSourceType to Table/Query
Set this RowSource:
SELECT NumCol FROM NumberTable
WHERE NumCol <= [Combobox1].Value
so it will show the first x entries.

Related

SSRS Expression to extract all Names in an Name Field

I have a query that pulls three fields, over 9000 rows (A-Z, names):
I am trying to extract by all "A" name Agencies, "B", and so on into Excel worksheets by each A,B,C,etc., once we render and save the report.
Can someone help with an Expression that will accomplish this?
Thanks,
jer
First create a calculated field in the dataset to get the first letter of each agency.
=Left(Fields!AgencyName.Value, 1)
Next, set up a table (aka tablix or matrix) with two row groups. The parent group should be sorted and grouped by the new FirstLetter column. In this group's properties, set it to break at the end of each group. Also set the PageName property to be the FirstLetter.
The child row group should be grouped by nothing so that it will show every detail row. Sort it by Agency name if desired.
What you should get now is a page for each letter and within each page a row for each agency. When you export to Excel it will create a sheet for each "page" and name them all accordingly.

Access VBA: How to count items of a ComboBox?

In my ComboBox I have some items already selected.
I would like to count them with VBA. I was expecting to find something like the following string, but I get Compile error: Argument not optional.
Me.<ComboBox_name>.ItemData.Count
I also thought to use the following string but it gives me 0 items:
Me.<ComboBox_name>.ItemSelected.Count
To count the options, it is:
Me!<ComboBox_name>.ListCount
or to be precise, in case you use column headings:
Me!<ComboBox_name>.ListCount - Abs(Me!<ComboBox_name>.ColumnHeads)
Comboboxes are generally used for selecting or showing the selection of a single item, whereas listboxes naturally support multiple selections.
That said, if you're linking a multivalued* table field to a Combobox, for example, you could have a Combobox with multiple selections. If that's the case, the only time the values will be available in the .ItemsSelected property is while the Combobox has focus and is dropped down.
A way to work around this is to assign the Combobox's .Value property to an array. The array will contain the selected values. You may count them by taking the upper bound of the array and adding 1:
Dim comboitems() as Variant
Dim count as Long
comboitems = yourcombobox.Value
' array is 0-based so add one to get the count
count = UBound(comboitems) + 1
If the array is multidimensional, you read the value this way:
' array is 0-based so add one to get the count
count = UBound(comboitems, [dimension]) + 1
' where [dimension] is a 1-based index equivalent to the 'column' of the data
I hope that helps!
*Note: multivalued fields are usually ill-advised, as they are poorly
supported by Access and usually mean you should be normalizing your
tables, i.e. breaking out the multivalued field into another table.

Access - Excluding first column from lookup values

I have this database and a field's lookup is set to comboBox with 'bound column' to 2 and 'column count' to 2.. My row source's first column is ID (AutoNumber), and my second column is Name(Text). When I go to Datasheet View and select a value it displays ID column value.
How to make it display a Name column value?
There are two basic ways to achieve this manually. This has to do with updating properties of the combo box. The particular properties are listed under Data or Format.
Return the ID as the first column, set the column count to 2, set the data bound to column 1, and define column widths with the first width = 0. Something like, 0";2" This way technically both columns display, but the first one has 0 width.
Or my preferance
Return the ID as the second column. Set the column count to 1 and bind the value to column 2. Doing this only the first column will display, but the 2nd column will be the value. The reason I prefer this method is that you can let Access determine the size of the drop-down column instead of defining it.
I just managed it in one way. In Design View, from dropdown list of your field (the one with lookup comboBox) select Lookup wizard.. Then go through the wizard, and that's it. However, I'm not sure how the wizard solves it.
Select the column1, column2, column1(again)
Set width = 0.01;.5;.5
column1 is not visible, but is the value you want in your field

Add "All" option to ComboBox used to filter for report in MS Access

I'm trying to follow Microsoft's example on how to add an "All" option to a ComboBox in Microsoft Access, but their article does not do an adequate job of providing guidance, aside from specifying the code.
What I'm trying to do is build a form that allows a user to select an option from a ComboBox (the options are generated from records in a table), and then build a report filtered based on the user's selected option. The ComboBox consists of 2 columns: the primary key/ID of the records and their displayable names.
I can't understand the VBA code Microsoft provides enough to figure out what is going on, but I would like the "All" option in my ComboBox to either have a blank primary key/ID, or one that = 0. That isn't the case, as selecting the "All" option when using the form results in the error message "The value you entered isn't valid for this field". This leads me to believe that the "All" text is getting filled into the primary key/ID column instead of the display column. The example instructs me to assign the display column number as the "Tag" property of the ComboBox - and in this case, my display column number is 2. However, this (and pretty much any other value I add) results in the aforementioned error message.
Any idea if Microsoft's example is even applicable to my case, or do I need to adjust their code somehow?
Check the Control Source property of your combo box. Sounds like it may be bound to a field in the form's record source. If you make it an unbound control (nothing in the Control Source property) you should be able to select any item from the combo's Row Source without Access complaining at you.
Say your combo's Row Source is a query like this:
SELECT id, disp_name
FROM YourTable
ORDER BY disp_name;
You can add an "all" row with a UNION query:
SELECT id, disp_name
FROM YourTable
UNION ALL
SELECT TOP 1 0, "**ALL**"
FROM AnyTable
ORDER BY disp_name;
AnyTable can be just that. If you happen to have a table which contains only a single row, use that one ... and you wouldn't even need the TOP 1 part. Just try not to use some ReallyBigTable as AnyTable.
Edit: Actually some ReallyBigTable would be fine if it has a primary key or other unique field which you can use in a WHERE clause to retrieve a single row:
SELECT id, disp_name
FROM YourTable
UNION ALL
SELECT 0, "**ALL**"
FROM ReallyBigTable
WHERE pk_field = 1
ORDER BY disp_name;
UNION ALL will return all combined rows. If you have any duplicate rows, you can thin them out by using just UNION instead of UNION ALL.

MS Access Dropdown List/Combo Box

This should probably be pretty simple but my Google-Fu is as yet unable to find an answer. I simply want to create a dropdown list in Access so that upon selection I can perform some action based on the value of the selection. For instance, I have a list of people and I would like to populate the combo box so that their names appear in the list but the "value" is set to their ID (the primary key).
It sounds like you might be asking how to display something in the dropdown other than the ID while keeping the ID as the returned data from the dropdown. If that's the case set the Bound Column to the ID field (usually 1) and (assuming the name field is next) set the Column Count to be 2 and the Column Widths to be 0";1" or 0";[whatever width you need].
You will need to hook into the onchange event for the dropdown list.
and from MSDN
How have you set the properties for your combo box?
Perhaps you could try setting (assuming you are pulling data from Table1 with fields ID and Field1
Row Source: SELECT [Table1].[ID], [Table1].[Field1] FROM Table1;
Row Source Type: Table/Query
Bound Column: 1
Column Count: 2
Column Widths: 0", 1"
and then hook into the onchange event as Chris Ballance suggests. The value property of the combo box is ID; the text will be what is in Field1.
OK, I figured it out even though it was a bit counter-intuitive. An Access Combobox can have as many values as you want (instead of just one key on value). By default all of the values are are shown in the list so you need to hide certain columns by setting their widths to 0. That is done via the ColumnsWidths property in the property pane. ColumnWidths takes a comma separated list of values which corresponds to the order of the columns in the list. I hope this helps someone.