Sequential numbering for each record - ms-access

I have contracts and I want each contract to have its purchase orders sequenced
I just can’t get it to work
What I tried to do is make a calculated field in my form using the control source
=DMax([PO],[POt],[POt].[Contract number])+1
By that I thought if I can make it read the biggest PO for that contract to add 1 to it
But I keep getting #name? Errors

Try with:
=DMax("[PO]","[POt]","[Contract number] = " & [Contract number] & "")+1
where [Contract number] is the field holding the current contract number.

Related

Access parameter query not returning records with specific value

Yesterday I asked a similar question, and thank you to those who replied. I'm creating this new question as I've worked a few things out and can hopefully provide more/better information, but still running into the same problem. I'm very, very new to Access and any kind of code or related terms so thank you in advance for your patience with me.
I'm building a query to search tbl: Inventory. There are no lookups built into the table. The parameters can be entered via combo boxes on a form by the user. The row sources for the combo boxes are distinct values from the coordinating fields in tbl: Inventory. I want the user to be able to fill in any/all parameters and get results, so I'm using LIKE "*" in my criteria of each parameter. All values in the parameters are text. In tbl: Inventory the fields are also all text (except the PK which is an autonumber). This is my SQL for the query:
SELECT Inventory.InventoryID, Inventory.SetID, Inventory.ItemName, Inventory.Period, Inventory.Color, Inventory.GarmentType, Inventory.GarmentSubType, Inventory.ATCShow
FROM Inventory
WHERE (((Inventory.Period) Like "*" & [Forms]![frmSearchInventory]![cboPeriod] & "*") AND ((Inventory.Color) Like "*" & [Forms]![frmSearchInventory]![cboColor] & "*") AND ((Inventory.GarmentType) Like "*" & [Forms]![frmSearchInventory]![cboType] & "*") AND ((Inventory.GarmentSubType) Like "*" & [Forms]![frmSearchInventory]![cboSubType] & "*") AND ((Inventory.ATCShow) Like "*" & [Forms]![frmSearchInventory]![cboShow] & "*"));
Please excuse the excess brackets, as I said, very new so I'm letting Access do most of the writing for me.
For some reason, no matter what combination of parameters are used, it will not return any records where Inventory.GarmentType = suit coat, and the record also includes a SetID--even if the only parameter entered is "suit coat". For records that do not include a setID and are type=suit coat, the record is returned. If the record includes a setID and is not a suit coat, the record is returned. Not sure if that is related, as SetID is not a parameter, but it's something I noticed.
I've tried changing "*" to "%" and LIKE to ALIKE and no records at all were returned.
Any ideas? Happy to provide any additional information. Thank you!

SSRS : Format (indentation) new lines in a textbox using expression

In SSRS, I have a textbox with value as below expression, Expression is within a single textbox and I need format the lines in that single textbox.
= "Test Example "
& vbcrlf & SPACE(10)+ "First Name," + " Middle Name," + " Last Name"
& vbcrlf & SPACE(10)+ "Address 1," + " Address 2," + " Address 3"
& vbcrlf & SPACE(10)+ "Instructions: " + " Please select your country from the list below so we can display the correct prices, delivery times and shipping costs for your shipping destination."
Current Output is:
Test Example
First Name, Middle Name, Last Name
Address 1, Address 2, Address 3
Instructions: Please select your country from the list below so we can
display the correct prices, delivery times and shipping costs for your
shipping destination.
I have to format the text to start at same point and Expected Output is below:
Test Example
First Name, Middle Name, Last Name
Address 1, Address 2, Address 3
Instructions: Please select your country from the list below so we
can display the correct prices, delivery times and shipping costs for
your shipping destination.
How can I change the expression to get expected output?
Thank you!
This is the one use for the Hanging Indent property. The trick to use a negative number to get what you want.
I'm not sure how this renders in various outputs - I think the formatting might be lost in Excel.

Ms-Access DLookup - how to I return only records from this year?

I think this should be simple, but I've been struggling for too long.
I have a form with a bound text box which I would like to return a value it has calculated. It calls on the table 'Training' which stores the variables Client, Standard and Date. Client is a string, standard is an integer and Date is in the format dd/mm/yyyy. I would like the box to return the sum of the Standard entries for this year.
So, if we've been out to see Client A last week and done one session and been out again today and done two, the table might look like:
Client A - 1 - 01/01/2017 <br/>
Client A - 1 - 12/01/2018 <br/>
Client A - 2 - 17/01/2018 <br/>
Client B - 1 - 15/01/2018
I'd like my box to return the value '3', ignoring Client A's training last year or the training this year of any other client.
I can get the box to correctly distinguish between clients, but not between years using this code:
=DSum("[Standard]","Training","[Client] = '" & [Client] & "'")
That selects the client from the training table, based on the client record currently selected in the form. It sums all the training that client has ever had - so in the example above returns '4'.
What I am struggling with is how to restrict the year. I've tried a number of variations on:
& "Year([TrainingDate])=#" & Year(Date())
but always get either Name? or Error. What am I doing wrong?
With thanks,
Matt
Use:
=DSum("[Standard]","Training","[Client] = '" & [Client] & "' And Year([TrainingDate]) = Year(Date())")
year is an integer -- try Year([TrainingDate])= " & Year(Date())

MS Access Date Grouping is not working in report

I have created a simple Microsoft Access 2007 app of receiving and paying vouchers, everything is working properly but one thing that my mind doesn't solve.
I have created a report template of "Receiving Amount" where I want report be grouped in respect of receiving date. I have added a field named "Receiving Date" in "Group, Sort and Total" and when I generate it, it doesn't group the content in respect of date.
Adjust your Grouping and Sorting to use the expression:
Fix([Receiving Date])
I found the solution.
The reason of not grouping date wise because Access could not understand the date, like Gustav said, format is just for display but actual value is different and Sergey S said "If the field with date contains time. you won't be able to group the report".
Finally, I had to remove time from the date and keep it clear to Access so it can group my report.
=MonthName(DatePart("m",[receiving date])) & " " & Format$([receiving date],"d"", ""yyyy")
Where receiving date is the field name.

DSUM in Access query yields Nulls in random records

I have a query (in MS Access 2013) that gives me the Sales for various Items by Date, for each day for the next 12mo. In another table, I have each Item with its known purchasing leadtime, say between 30 and 90 days.
I created a query, and for each Item, I calculated the future date according to the leadtime, using:
FutureDate: DateAdd("d",[Leadtime],Date())
I validated all Items exist in the Sales query, and all FutureDates are within the records that exist in Sales.
I need to calculate the sum of daily Sales between now and the calculated [FutureDate] for each Item, to get the total amount of Sales expected within the unique Leadtime of each item.
I tried function DSUM() with weird results:
The query of daily Sales already excludes any past sales, so my first try was:
TotalSalesInLeadtime: DSUM("DailySales","Sales","[DayOfSale]<=#" & [FutureDate] & "# AND [Item]='" & [SearchedItem] &"'")
For some Items, [TotalSalesInLeadtime] calculated correctly, while others evaluated to Null.
Then I tried:
TotalSalesInLeadtime: DSUM("DailySales","Sales","[DayOfSale] BETWEEN #" Date() "# AND #" & [FutureDate] & " AND [Item]='" & [SearchedItem] &"'")
The results now were reversed. [TotalSalesInLeadtime] values now showed correctly for the items that previously showed Null, and were Null for items that previously evaluated correctly.
I never figured out why DSUM() did this.
To work around the DSUM() glitch, I went with an embedded subquery, which yielded all the values correctly, albeit at a significant performance hit:
SELECT [PurchItem],
(SELECT Sum([DailySales]) AS SumOfSales
FROM [Sales]
WHERE ([Item]=[LeadtimeItems].[PurchItem]) AND ([DayOfSale] Between Date() AND [LeadtimeItems].[FutureDate]))
As TotalSalesInLeadtime
FROM LeadtimeItems
If anyone has a clue why DSUM may behave this way, I'd appreciate the help. DSUM, when it works, certainly seems to go faster.
When "gluing together" SQL statements (or fragments) that include date literals enclosed in hash marks (#), one must bear in mind that Access SQL and VBA will always interpret ambiguous date literals as mm-dd-yyyy regardless of the system-wide date format. So on a machine where Windows has been configured to use dd-mm-yyyy, an unambiguous date like April 30 will work okay
?DateSerial(2013,4,30)
30-04-2013
?"#" & DateSerial(2013,4,30) & "#"
#30-04-2013#
?Eval("#" & DateSerial(2013,4,30) & "#")
30-04-2013
...but for the next day, May 1, things don't work so well
?DateSerial(2013,5,1)
01-05-2013
?"#" & DateSerial(2013,5,1) & "#"
#01-05-2013#
?Eval("#" & DateSerial(2013,5,1) & "#")
05-01-2013
So the lesson is that any time we "glue together" date literals we must ensure that those dates are in an unambiguous format like yyyy-mm-dd. With regard to this particular question, we need to use
TotalSalesInLeadtime: DSUM("DailySales","Sales","[DayOfSale]<=#" & Format([FutureDate], "yyyy-mm-dd") & "# AND [Item]='" & [SearchedItem] &"'")