Am a newbie in Microsoft Access 2016 making a database system for processing loans.
I have made two fields:
ID e.g: 001 with datatype number and
NRC (This is the official National Registration Card number in my country e.g: "123456/78/1" )
I now want to generate a new field:
LoanNumber from the fields 1. ID and 2. NRC mentioned above.
From the examples above, I want this new field to be composed with two parts concatenated together; that is "ID-first part of NRC before the first '/' ".
e.g: LoanNumber : 001-123456
What code in the expression builder will will help me achieve this?
A number datatype value cannot be saved with preceding zeros. Use Format function to manipulate number. This can be done in a query or textbox but not in table because Format function is not available for Calculated field type.
Format([ID], "000-") & Left([NRC], 6)
Related
I have brought a table from an Authority database into Excel via power query OBDC type, that includes fields like:
Date - various
Comments - mem_txt
Sequence - seq_num
The Comments field has a length restriction, and if a longer string is entered, it returns multiple rows with the Comments field being chopped into suitable lengths and the order returned in the Sequence field as per extract below. All other parts of the records are the same.
I want to collapse the rows based and concatenate the various Comments into a single entry. There is a date/time column just outside of the screen shot above that can be used to group the rows by (it is the same for the set of rows, but unique across the data set).
For example:
I did try bring the data in by a query connection, using the GROUP_CONCAT(Comments SEPARATOR ', ') and GROUP BY date, but that command isn't available in Microsoft Query.
Assuming the date/time column you refer to is named date_time, the M code would be:
let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
#"Grouped Rows" = Table.Group(
Source,
{"date_time"},
{{"NewCol", each Text.Combine([mem_text])}}
)
in
#"Grouped Rows"
Amend the Source line as required.
I've 3 fields which contain only text. However, i want to add a calculated field which counts the number of commas in each of these 3 fields and displays it separately in the adjacent column. The snippet of SQL i use is shown below. How can i build the calculated field?
SELECT week, client_I, client_II, client_III
FROM quality_control_test;
Please advise!
well, you can "count" the number of a given character in a string, by using this:
length(c) - length(replace(c,',',''))
I'm assume you can figure out how to leverage that for your own query ;)
I have an Access database that we use to house Worker's Compensation Accident Information. One of the required fields is an OSHA recordable number that is sequential starting with "01" and the two digit year of the accident (ex. 01-14).
I need to be able to programmitically look into my table see what numbers have already been used and find the next number in the sequence. It also needs to reset to 1 at the beginning of a new year.
Example:
table reads
01-14
02-14
03-14
The new number that populates the textbox should be 04-14
Help!
Given that you have a multi-user database, see insert query with sequential primary key or Access VBA: Find max number in column and add 1 for code to get the next sequential number.
You can use Year and the seed number to create the next OSHA number. You can reset the seed number on year change.
DMax is a possibility, but I strongly suggest you do not use it in a multi-user database.
From what you have described, it sounds like the OSHA number should be generated as and when needed instead of being assigned and stored when the table row is created. My suggestion would be to just have the primary key (accident_id) be an autoincremented long integer, the standard practice in Access. And also you need an accident_date column to be a datetime or similar. Or at the very least an accident_year column. Then when you need an OSHA number (say in a report), just have some VBA to generate it using the primary key--accident_id--and the accident_date or accident_year column. You will be taking advantage of the fact that Access autoincremented primary keys are never re-used--even when their rows are deleted, those numbers are never recycled to be used in other rows. So given a long integer primary key, and a date, you can always reproduce the exact same OSHA number, with a simple algorithm something like the following:
function osha_number(accident_id as long) as string
accident_year = ... ' get (last two digits of) accident year from accidents table using ID
year_first_accident_id = ... ' get ID of first accident of this year
year_this_accident_num = accident_id - year_first_accident_id + 1
osha_number = year_this_accident_num & "-" & accident_year
end function
I could use some help in inventorying some online purchases.
I would like the information in column A to be separated into the following:
Vendor name; item description; eBay item #; purchase price; shipping cost; purchase date
example:
ldean747; MEN'S WILLIAM BAY" "; 260725743398; 10.50; 0.00; 01/28/11
I'm getting hung up because some of the products do not have shipping cost (which would be the second dollar amount you see in the picture).
Any easy way to do this rather than going through and copy paste, transpose on each purchase?
You have a couple of challenges here
dynamic data set format: 3 text fields followed by 1 or 2 numeric fields (vertically)
multiple field seperators / delimiters across your data set
1st field: '()''
2nd field: '|'
3rd field: ':'
You could now start to create formulas which extract the relevant parts of each field using functions like =LEFT(), =MID(), =RIGHT(), =SEARCH(), etc. which for some cases (3rd field) is pretty straightforward, for others can get a bit complex ...
Concretely - the fields can be identified as following:
if the cell above is numeric AND I am alpha THEN I am 1st field
if the cell above is 1st field THEN I am 2nd field
if the cell above is 2nd field THEN I am 3rd field
if the cell above is 3rd field THEN I am product cost
if the cell above is numeric AND I am numeric THEN I am shipping cost
numeric / alpha: =TYPE(), extracting substrings seperated by seperation characters is well covered here at SO
Alternatively you could start to write a VBA program that does the same job for you
meta code:
loop through all rows
determine record type
process record type
So give it a try and come back with more questions.
I feel stupid asking this, but I really need an excample on how to get a value of a field in one table (in the end in my report) depending on a value of a field from an other table in Access.
So I have (for excample) a table:
Products and in my report I do a formule using the value of price (field of Products) and adding to that I must have the value of the field VAT-Type (a nummeric var, in the table VATS) depending on what is there in the record (of the one in the table Products) in the field VAT-Sort, also a nummeric var that must meet one of the values used in the field VAT-Type).
So in the report I must have something like:
Product: X Count Price'=(price+21%)'
where 21% comes from the dependensy between the field VAT-Type and VAT-Sort.
I know I can do something like result=select 'VAT-Sort' from 'VATS' WHERE 'VAT-Sort' = or equals 'VAT-type'
But how do I use it in a report of Access to get the right result?
You can use DLookUp:
Numeric data type:
DlookUp("Value","Vats","Vat_Type=" & Vat_Sort)
Text data type:
DlookUp("Value","Vats","Vat_Type='" & Vat_Sort & "'")
Or you can base your report on a query, say:
SELECT Value, Other, Field, names FROM Products
LEFT JOIN Vats
ON Products.VAT_Sort = Vats.Vat_Type
Edit re comments