Problems with my Dlookup and Dmax - ms-access

I'm trying to solve a problem in Access-2010. A Student number consists of 1314 followed by a 4 digit number.
The 4 digit number is sequential i.e. each one is 1 higher than the last. So, if the last Student number in use was 13140925 then the next should be 13140926.
The formula at present looks like this:
=1314&DMax(“Right(StudentNumber,4)”,“TBLStudent”)+1
However, this generates an error. I've also tried this:
=DLookUp(“Left(StudentNumber,4)”,“TBLStudent”&DMAX(Right(“StudentNumber,4)”,“TBLStudent”)+1)
Which I prefer as the 1st 4 digits can be anything and not just 1314. Anyhow, can someone please help me to identify the mistakes?

This should do:
=Left(DLookUp("StudentNumber","TBLStudent"), 4) & Right(Val(DMax("StudentNumber","TBLStudent")) + 1, 4)

Related

Matches where an occurrence of X is Y but the corresponding Z is missing

I am trying to create a formula (or script) that is able to find all the occurrences of a plate number and return 1 if 'BOUGHT' has been found, but 'SOLD' is missing for that plate number.
The dataset that looks like this:
Column A is a list of plate numbers and B is the type ('BOUGHT' or 'SOLD').
I need to find the plate numbers for which there is a 'BOUGHT' but no 'SOLD'.
I tried using the formula below (and many others):
=ARRAYFORMULA(IFERROR(IF(
((VLOOKUP(A2:A,A:B,2,0)="VÉTEL")
+
(VLOOKUP(A2:A,A:B,2,0)="ELADÁS"))<>2
,1,0)))
Since nothing seems to be working, any help would be highly appreciated.
I created a sample worksheet, which can be found here.
Try below formula-
=ArrayFormula(IF(COUNTIFS(A2:A,A2:A,B2:B,"BOUGHT")>0,IF(COUNTIFS(A2:A,A2:A,B2:B,"BOUGHT")*(COUNTIFS(A2:A,A2:A,B2:B,"SOLD"))=0,1,""),""))
See your sheet.

Use IIF and LIKE statement in critera column in queries, MS Access

I have homework from Microsoft Access for school and one of the tasks was to make a search form in query, where you type for example 1. grade, 2. grade or 1st year, etc... But the field contains the name of the classes such as IT1, IT2, E1A, E3C, etc... So I could not just make a search form with [Enter Class:] or Like [Enter Class:]&"*" in the criteria column. So I was thinking, that I can use the IIF statement but it doesn't work how I imagined. I think there is a problem with the LIKE statement. I read on forums, that the IIF statement should be used in the field column but I tried the simple examples in the criteria and it worked just fine. So my question is, how I can make a search form, where I type numerous letters with one certain number in it BUT only the number will be read and returned with the same number in classes. Example: I type to search 1. grade and the value will return classes IT1, E1A, E1B, E1C, E1D. This is the line I used in the criteria column:
Like IIf([Enter the grade:]="*1*";"*1*";IIf("*2*";"*2*";IIf("*3*";"*3*";IIf("*4*";"*4*"))))
Just to qualify, I'm beginner in access and databases overall, so there is big possibility, that I'm missing something.
Thank you for help! Cheers!
Assuming input will always start with a number and you want all values containing that number, consider:
WHERE fieldname LIKE "*" & Val([Enter grade]) & "*"
Also assumes values contain only single digit.

Access 2013 Count

I am working on a report in Access 2013 I need to seperate the first 20 records in a column that contain a value and assign a name to them. Such as at 1-20 I need it to insert Lot 1 at 21-40 need to assign Lot 2 etc... The report needs to be separated by lots of 20. I can also just insert a line when it reaches sets of 20 without a name if that makes it easier. Just need something to show a break at sets of 20.
Example: As you can see the report is separated by welder stencil. When the count in the VT column reaches 20 I need to enter a line or some type of divider to separate data. What our client is asking for is we separate the VT in sets of 20. I don't know whats the easiest way to accomplish this. I have researched it but haven't found anything.
Example Report with Divisions
Update the report's RecordSource query by adding "Lot" values for each row. There are multiple ways of doing this, but the easiest will be if your records already have a sequential, continuous numerical key. If they do not have such a key, you can research generating such sequential numbers for your query, but it is beyond the scope of this question and no details about the actual data schema were supplied in the question.
Let's imagine that you have such a key column [Seq]. You use the modulo (mod) and/or integer division operators (\ - backslash) to determine values that are exactly divisible by 20, e.g. ([Seq] - 1) mod 20 == 0.
Generate a lot value for each row. An example SQL snippet: SELECT ("Lot " & (([Seq] - 1) \ 20)) As LotNumber ...
Utilize Access report sorting and grouping features --grouping on the new Lot field-- to print a line and/or label at the start of each group. You can also have the report start a new page at the beginning or end of such a group.
The details about grouping can be found elsewhere in tutorials and Access documentation and are beyond the scope of this question.

Computed Column Formula and how it can work base on condition

I have this challenge. I want to achieve a formula in a computed column. Currently my formula is: ((((([sponsorID]+' ')+substring(CONVERT([varchar],datepart(year,[DateCreated]),(0)),(3),(4)))+'-')+'0')+CONVERT([varchar],[ID],(0)))
Where: sponsorID, DateCreated, ID are columns in my table PatientInfo.
A sample of what the formular produce is PVT 11 10567
My ID column auto increment
Now The total no of record in my table called PatientInfo is getting to 500,000. and the formula i was given is [SPONSORCODE YEAR - 4 DIGIT]. It must not exceed 4 digit!
How do i achieve this formula in such a way that the id stops when a year ends and start afresh in a new year. i.e. patient folder no can be PVT 10 0128 ....... and PVT 11 0128. this is because in a year the total no of new patients will not exceed 4 digits. aside from the existing patients.
PLEASE Kindly assist. i hope i have provide a clear picture of my challenge. if there is a better way to achieve this, please assist.
awaiting your reply.
Would it work to use the last 4 digits of ID? For the ID part of the expression, you could use:
RIGHT('000' + CONVERT(varchar,[ID]),4)
Of course, you could get duplicates if you ever inserted more than 9999 rows in a particular year.
You can't using a computed column based on ID
You'd need a separate incrementing column per year and per sponsor that allows only 0000-9999. Then, use this in your computed column.
In the next version of SQL Server, you can use a sequence. Until then, you could use a sequence emulator: http://blogs.msdn.com/b/sqlcat/archive/2006/04/10/sql-server-sequence-number.aspx

Show difference in records - MS Access 2007

I have a subform with the following layout:
ID---Count---Difference---Weight---Difference
Populated with data looks like this:
ID---Count---Difference---Weight---Difference
1----5--------------------8.3----------------
2----9--------------------12.3---------------
3----16-------------------17.8---------------
How can I tell the difference between a record value and the one before it? Using the previous example, I'd like the Difference controls to look like so:
ID---Count---Difference---Weight---Difference
1----5-------0------------8.3------0---------
2----9-------4------------12.4-----4.1-------
7----16------7------------17.8-----5.4-------
As you can see, since record ID 1 is the first record, the difference is 0; however, ID 2 shows a Count Difference of 4 (9-5) and a Weight Difference of 4.1 (12.4 - 8.3); and ID 7
shows a Count Difference of 7 (16-9) and a Weight Difference of 5.4 (17.8 - 12.4).
Also note that the ID #'s do not necessarily increment one-by-one (there can be gaps).
How can I achieve the desired results? Expressions? VBA?
Any help with this is greatly appreciated!
Found my answer. Method 2 in this article described exactly what I need.