Is there a name for a data type which can be one of a set? - terminology

Is there a name for a data value which can only be one of a number of items in a set?
For example, a boolean could be described as a xxxx with possible values of [True,False]. The state of matter could be described as a xxxx with the possible values [Solid,Liquid,Gas]. Size could be [XS,S,M,L,XL,XXL]
I know it's not really a primitive data type - it's a sort of meta-type. The actual value stored is the value of the item in the set. But I want a word for 'something which is always one of a given set'...

You might be thinking of an enumerated type. These are present in many programming languages.

Related

How to get the formatted autonumber value in MS Access to appear in form control as a formatted value?

I have an ID field with an AutoNumber Data Type that has a custom format defined in the Field Properties (A-00001, A-00002, etc).
I wanted to look up the formatted value and display it in a form textbox control.
ServiceNumber_entry = DLookup("ServiceID", "ServiceRecord", "SNID = '" & Forms!ServiceEntry!PartSN_entry & "'")
Using the line above, it returns just the number value and not the full formatted value (i.e. 1 instead of A-00001). What am I missing?
Existing comments all contain good information, but it can be useful to put it all together. The comments also failed to describe the context in which Access automatically copies and applies properties like Format, so that the comments (even if correct) might seem contradictory. My explanation is a bit verbose, but hopefully avoids further confusion.
The purpose of the Format property for any value in Access is to define how the data is displayed. This is true of a table column presented in a datasheet or a textbox control on a form. The Format does not define how values are stored, either in storage or in memory. The same value could be formatted and displayed differently without affecting the underlying stored datum. In this case, the Autonumber values are really Long Integer values. (They are not stored with a preceding "A-", which would require the values to be strings and would ruin Access's ability to automatically increment the values.)
Access attempts to provide a consistent view of the data and reduce tedious programming details by automatically copying the Format property to queries and form controls, just as it does with many other metadata properties. For instance, if you drag the AutoNumber field onto a form in design mode, it will automatically copy the Format string from the column to the TextBox control's Format property. In contrast, if you include the same column in a query, the query's column property sheet also has a Format property, but it will remain blank by default. However, when the query is executed, it will indeed be displayed with the format defined on the table column. This behavior does not mean that the data values themselves "have a format", rather Access is just doing its automatic work of looking up default formatting values from the table definition and applying it to the query's output. (It can do this if there is a simple one-to-one table column to query column relation, which is the usual case for queries.)
DLookup() is a Visual Basic (VBA) function. It is necessary that such functions handle the "raw" data independently of metadata, like Format (or Caption, Text Alignment, etc.). For coding purposes, a programmer expects to retrieve the actual long integer value from the column, not a formatted string value like "A-00001". The function will not only skip the format, the formatting information is completely dropped from data values. In a programming environment, data can be combined and manipulated and the concept of "format" becomes lost and/or meaningless. Even though in this case it might seem obvious, DLookup makes no assumptions about what you're going to do with the data and so just returns the integer values.
If your form TextBox control was not originally placed on the form specifically for the AutoNumber field, Access would not know to the copy the Format property. It would just display the integers from DLookup() as basic integers. However, you can manually set the TextBox's Format property to match the table column's Format property exactly to get back the expected values.

lookup in ssrs and return a value

I have a table with three columns, in column 1 I have a name and column 2 I have a quantity.
I want to look up column 1 and return the value in column 2.
I used to the expression below and it wouldn't return what I wanted.
=Lookup(fields!NAME.Value, "Paul" ,1 , 0)
Could anybody tell me what expression I need to use?
You are close, sort of. To use the Lookup function properly, you need to change some things. Here is an example using the Lookup function.
=Lookup(Fields!Field1.Value, Fields!Field1.Value, Fields!Field2.Value, "DatasetB")
It takes 4 parameters. The first is the field/value from the current (in scope) data set that you want to be the value to match in the lookup data set. The second is the field in the lookup data set to match on. The third in the field to return when a match is found, and the last parameter is the name of the lookup data set.
Based on the expression in your question, it may actually work like this:
=Lookup("Paul" , Fields!NAME.Value, Fields!QUANTITY.Value , "DataSet2")
Of course, hard coding the name in the first parameter is probably not what you want to do.

How to add case-sensitivity to a Combo box in MS-Access?

I have a combo box with a RowSource. When it displays, it shows a list of items that come from a query. The query has two columns. When the user chooses something, the first column is stored in the table, but the second column is displayed (works fine).
When you come to the form and view some existing data, it shows the display value from the query (RowSource) like it should. Works nice most of the time.
The challenge is that one of my combo boxes deals with case-sensitive keys. The wrong stuff is getting shown.
Here is some contrived data:
id value
[a1] [Apples]
[A1] [Oranges]
The underling table is like this:
MyTable
id: int
...other fields...
fruit_key: string
When the fruit_key column contains, "a1", I want to see Apples. When it contains "A1", I want to see Oranges.
What's happening is that I am always seeing Apples because it's doing a case-insensitive match.
How do I change this to case-sensitive?
You can't, except with kludgy workarounds. From How To Perform a Case-Sensitive JOIN Through Microsoft Jet:
The Microsoft Jet database engine is inherently case-insensitive.
And there is no way to change that.
In WHERE conditions and JOINs in queries, you can work with binary string compare: StrComp(Field1, Field2, 0) = 0.
But here, with the bound combobox, your best choice would be to convert the fruit_key string into e.g. a hex string (see Hexadecimal Expansion in the article).
In the rowsource of the combobox you could use a computed column, but in the table you want to edit with the combobox, you'd have to actually store the hex string in addition to the fruit_key, because you can't edit a computed column.
I'm not sure if or how the Binary Field method would work in your case.
All in all you'd probably be better off by
"doing it differently" so that you don't need the case-sensitive data, or
not using Jet as backend, but a server database, where you can set a case-sensitive collation.

SSRS chart series labels: Field!axisfield.Value not current value

I am trying to dynamically format the labels on my SSRS charts based on the underlying value. I'm trying to do this in two scenarios, one to format dates as ordinals and another to choose the appropriate number of decimal places based on actual values present. However, when I use the expression editor with an expression something like this...
=IIF(MAX(ABS(Fields![axisfield].Value))<2, "0.0%","0%")
...the Fields![axisfield].Value is always returning the first value from the dataset, meaning, in this example, if the first value is less than two, the labels will be formatted with one decimal place, even if it is the only one less than two. (So the 'MAX' function is essentially irrelevant.)
That example is attempting to set the overall formatting based on the largest data point in the series, in this next one I'm trying to format each label separately to get Ordinal dates (i.e. 1st, 2nd, etc, and yes, this formula is incomplete: it doesn't need to be to illustrate the problem):
="dd"+IIF(DatePart("d", Fields!date.Value)=1,"\s\t"
,IIF(DatePart("d", Fields!date.Value)=2,"\n\d"
,IIF(DatePart("d", Fields!date.Value)=3,"\r\d"
,"\t\h")))
This will give 1st, 2st, 3st and so on, as the first row in the dataset is for the first.
So, my question is, how do I get round this and, in the first example get the true maximum, and in the second reference the actual value being formatted?
Thanks!
I've had the same issues with using custom functions for setting label visibility. (see my entry for this: How to Display Only 1 Value Label in SSRS 2012 Calculated/Derived Series? )
I believe the issue is that data and fields are bound to the underlying data series but are not bound and accessible within the label itself.
You should be able to set the formatting in the function for the series data itself (as in the 2nd example) and then just set data labels, which will use the underlying series field value. An example with your data might be something like the following, which returns the values with the format:
="dd"+IIF(DatePart("d", Fields!date.Value)=1,Format(Fields!date.Value, "\s\t")
,IIF(DatePart("d", Fields!date.Value)=2,Format(Fields!date.Value,"\n\d")
,IIF(DatePart("d", Fields!date.Value)=3,Format(Fields!date.Value, "\r\d")
,Format(Fields!date.Value,"\t\h"))))
In the first example, you can get the max value to referring to the Dataset, as opposed to the field. Your code would then be:
=IIF(ABS(MAX(Fields![axisfield].Value, "YourDatasetName"))<2, "0.0%","0%")
(I changed the order of operations for Abs and Max because you have to use an aggregate function when referring to the whole dataset. Only then can you refer to the specific value.)

Entering "more than" (>) into a number field - database design

A client is looking to have a number field in a database that goes from 1 - 10. However, they would also like the option of "more than 10". Are there any best practices for adding this to a number field (integer) or is it even possible?
This feels like an inane and simplistic question and I'm hesitant to ask it but searches have revealed nothing and I feel like I may be missing a simple trick.
No, not with Access (and most other database applications) anyway. Number fields can only contain valid numbers (or nothing, if NULL is permitted), and neither "more than 10" nor "> 10" is a valid number.
Years ago I did a bit of work with FileMaker Pro and I remember it being quite "loose" in what it would allow to be entered into a field of a given "type". The field's "type" seemed to be more of a "suggestion" as to how an entry was to be interpreted. That opened up a certain degree of flexibility (to handle cases such as yours), but it also often left the user vulnerable to whatever assumptions the software made when interpreting a peculiar value.
In any case, "> 10" would have to be handled as a special case, so you'd probably do just as well to make the field a text field and use a combo box to select the values
1
2
3
...
9
10
more than 10 (or "> 10")
If you want to limit the user's selection to a valid value, i.e. a numeric value between 1 and 10 or a value of "more than 10", I would:
Create a lookup table with two fields ID (long), RecValue (text).
The table will have 11 records, where ID will have the values 1 to 11 and RecValue "1","2",..."10","more than 10".
Use a combobox for the data entry:
RowSource=
Bind on the ID field but show only the RecValue field.
Set "Limit to list" property to TRUE.
The user sees text, but behind the scenes you are using a numeric value.