Access - Field size for numerical field? - vba

With text boxes, you can set field size on how many characters can be entered.
Is it possible to do this to a numerical field?

No.
What you can do is to apply a validation rule to your number field in the table.
Like:
Len([enter your field name here])<=4
Plus a validation message:
Number should be 4 digits at most
There's other option too like applying a Before Update event in your form that you use to maintain the data.
And another possible option might be to apply a data macro.
Can't help you on that one as my Access version is pretty old.

You could use the format property. Another option would be to treat the field as a text box and the format property. Then when you want to use the value numerically use the val function.

Related

Fields on form, selected from data source are not available when using Me

I have two fields on a form. Field 1 is auto number field named 5sID. Field 2 is a lookup field named 5sType.
When I open the VBA code for both the oncurrent and on open, I try to reference either field with a "Me.5sID" or "Me.5sType". In either case when I type in the "Me." the auto list shows the other eight fields in the table, but not these two.
I have used this for years on both datasheets or continuous forms. There are only the two fields on the form and they were selected from the table field list in the design view.
If I change the name on the Other tab of the property options, the fields then appear.
I have now rebuilt the table and the form, I have created a database and linked to the same table and still get the same results.
If I add another short text field it shows up when I type "Me." in VBA, but any other type of field does not show up.
Naming an identifier with a number as first character is a bad idea! Always start with a letter!
On Access 2013 that creates a compile error as the compiler expects a=as he interprets.5as a decimal-number.
That worked for you on older versions? Hard to believe!
As workaround use square-brackets like on identifiers containing spaces or other crap.
Me.[5sID]
or turn onShow hidden Elementsin Object-Browser , what fixes Inteli-Sense and creates automatic brackets. Seems like this is a way to create hidden members ;)

Is there a way to use variables in vba to identify MS-Access report fields?

I am not a programmer, but have been tasked with doing this anyway! We are working on a research project that involves testing properties of different samples. I am trying to create a form that will generate a custom report based on what the user chooses. So, I have multiple text boxes and check boxes to allow the user to define the query parameters (e.g. composition of the sample must contain at least 5% component A) and choose what data they are interested in seeing in said report (e.g. show pH, color, but not melting point). I have successfully created code to generate the query, then generate a report based on that query, but the report defaults to column widths that are generally too big (for example, the pH column width is 3 inches, it only needs to be about 1). I would like to be able to fix this, but have not been able to figure out how. At the same time, some of these fields contain numbers that are averages of multiple test results, so I would like to limit the number of digits shown, and display them as % where appropriate. I started with just fixing the column width issue:
I have tried to make a collection of the fields that are included, then loop through the collection and set column widths, but cannot figure out how to identify a field with a variable:
If I know the field name I can do this:
Reports("ReportName")!FieldID.Width = 200
But if I have a collection of names, FieldNames, or a string VariableName, none of these work, giving me an error that FieldNames or VariableName is not a valid field in the report:
Reports("ReportName")!FieldNames(1).Width = 200
Reports("ReportName")![FieldNames(1)].Width = 200
Reports("ReportName")![VariableName].Width = 200
Is there a way to reference a field name with a variable?
Alternatively, I thought there might be a way to loop through all fields and set widths - this would involve looking up a column width for each field, which I thought to do by adding a key to a collection of column widths. But I cannot find a way to do that, something like:
For each Field in Reports("Report")
Field.Width = ColumnWidthCollection(Field)
Next
This hangs up on the Field.Width line, with "invalid procedure call or argument", which brings me back to how to reference a field name with a variable.
Any help would be greatly appreciated!
Try with:
Reports("ReportName")(VariableName).Width = 200

SSRS Colour Fomatting across multiple columns

I've created a SSRS report to examine whether certain fields contain a specific value using a simple case, when statement with the values returned being 'Yes' or 'No'. I'd like the cells to be coloured yellow with the value is a 'Yes'. (See Sample Table).
I know I can do this using the function IIF(Fields!Result1.Value="Yes","Yellow","Transparent") but for a table with multiple columns (>60), is there a way to copy the background colour formatting without having to write the function for each column?
If you want to compare the value of each text box/cell with "YES" then you can use the ME.Value reference.
There is little documentation on ME (https://msdn.microsoft.com/en-us/library/dd255285.aspx?f=255&MSPPError=-2147217396)
=IIF(ME.Value = "Yes", "Yellow", "Transparent")
To access the value of the current text box, you can use the Visual
Basic built-in global Me.Value or simply Value. In report functions
such as First and aggregate functions, use the fully qualified syntax.
Unfortunately, ME does not seem to be fully implemented - it causes errors when used in places that were not created to use ME correctly. An ACTION (i.e. Go To URL) that uses ME will fail with an error of an unknown reference.

Need a simple search function to display most common value in a column. (with ambiguous choices)

I have a very large array of data with many columns that display different outputs for the values presented. I would like to add a row above the data that will display the most common occurring value or word below.
Generally I would like to have each top of the column (right under the column label in row 1) have the most common value below. I will then use this value for various data analysis functions!
Is this possible, and if so, how? Preferably this will not require VBA, but simply a short code in the cell.
One caveat: The exact values may vary, so there is no set list where I can say "it will be one of these."
Any ideas appreciated!
Try a series of =COUNTIF(A:A,"VALUE TO SEARCH") functions if you want to stay away from VBA.
Otherwise, the best method would be to iterate through each column via VBA. With this method, you can even count the "varying" values and return the count and/or the value itself.
http://www.excel-easy.com/examples/most-frequently-occurring-word.html
This is a single formula you would write at the top of each column. Does not require VBA. You can replace the set range to an entire column, such as (A:A) instead of (A1:A7).
If you mean an array as in a data type, it could work differently but it depends what you're trying to do.
With data from A3 through A16, in A2 enter:
=INDEX($A$3:$A$16,MODE(MATCH($A$3:$A$16,$A$3:$A$16,0)))
This will work for text as well as numbers. Adjust this to match the column size.

Best way to handle multi-valued fields as a view/grid

In several notes applications, instead of handling related data as separate documents, if the size of the data is small (less than the 32k limit), I'll make several multi valued fields and display it in what I call a "List Panel". It's a table where each column displays one multi-value field. Since fielda(1) goes with fieldb(1) that goes with fieldc(1) there is a concept of rows. (I did a similar thing in my auditing routine discussed here )
It is always assumed that each field has exactly the same number of elements.
All the multi-value fields are then stored on the single document. This avoids several coding conventions that made my eyes bleed like having date changed, who changed it, new value fields for each field we wanted to audit. Another thing that this kept to a minimum was having to provide multiple fields for the same thing that locked you into a limit. Taxrate1, Taxrate2, Taxrate3, etc...
In my "Listpanel" the first column is a vertical checkbox. (One for each element in my lists) This is so I can select one item to bring up and edit, or select multiple values to delete "rows" or apply some kind of mass change to them.
What would be the best way to handle this under xPages to get this functionality? I tried making a table but am having the devil of a time to get the checkboxes to line up with their corresponding data items.
Views and dojo-grids seem to assume we're using a document for each row.....
This TableWalker may provide what you want http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Tutorial-Introduction-to-XPages-Exercise-23
It was created when XPages was all very new, so it's SSJS rather than Java. But if you're comfortable wiith Java, converting it probably won't be a challenge.
You could use a repeat control to display the values and build a table using the table row tags in the repeat. You would want to calculate the id of the checkbox to be able to take an action on that selected row. The repeat var would be just one of your multi-value fields and you use the index of the repeat to get the value for that row from the other multi-value fields.