I would like to create a Custom ID in format, "SACYear-Sequential Number", in an Access 2013 Table (Table Name = poledata) when records are appended into that Table.
eg. SAC18-1 (18 means 2018)
I have researched and found the code as below. As advised, I have to add 2 new fields in the Table, alternate_id_seq and alternate_id. However, errors show up for the following lines.
Expression = "SAC" & Year(Date()) Mod 100 & "-"
Look Up A Record In
Select pd.[alternate_id_seq]
FROM poledata AS pd
ORDER BY pd.[alternate_id_seq] DESC;
What's going wrong with them?
Related
Here is a example table in Excel:
ID Name Account
1 Jon 001
2 Snow 002
3 Alive 003
I want to create a SQL according to account. It looks like,
SELECT * FROM CUSTOMER_TABLE WHERE ACCOUNT=' ';
Is it possible to make system could fulfill ACCOUNT=' '? Like system could input each value automatically.
It should like WHERE ACCOUNT='C1', ACCOUNT='C2', ACCOUNT='C3'...
I assume you copied your accounts into a range like Range("E1:E10").
Then you can use a for loop to change accounts for every turn.
Change your Query as,
SQL_Query = "Select * From Customer_Table Where Account ="
then try a For Loop.
Dim Query as String
For i = 1 to 10
Query = SQL_Query & Cells(i,4).value
'Do your query here.
'Be careful about that your results should be copied under the last row.
'Otherwise only the last one will be shown.
Next
im trying to get the lowest available unique value but with some parameters.
i found this
and my statement will look like this
SELECT MIN(t1.cloakroomnumber + 1) AS nextID FROM Wardrobe_CloakTable t1
LEFT JOIN Wardrobe_CloakTable t2
ON t1.cloakroomnumber + 1 = t2.cloakroomnumber
WHERE t1.payingcustomerID = 2 AND t1.cloakroomsection = 'B' AND t2.cloakroomnumber IS NULL
but this is returning something that is not correct at all.
So the question is where should i put my WHERE to the MIN argument.
my tables are like:
ID (unique not important)
payingcustomerID (FK - thats why i need to get lowest for just 1 customer)
deviceID (not important)
terminalnumber (not important)
qrcode (not important)
cloakroomsection (defines if query is inserted in the same physical section)
cloakroomnumber (defines the unique number but its only unique in the
way that its unique in the same section AND for the same
paycustomerID)
if i have 5 different cloakroomnumbers in my database with same cloakroomsection and same payingcustomerID looking like
1
2
3
5
6
i want to be able to get number 4
the statement in the start i got from the other post is working correctly without my try to manipulate it. but its not taking into account payingcustomer and cloakroomsection. thats what im trying to add.
I have a dataset that is grouped by the CustomerId with multiple row information for each CustomerId.
I'm trying to create a numbering for each group (customerId) that gets created sequentially and then a total of groups.
So basically I am looking for the report to calculate that there will 5 groups here and then go 1 of 3, 2 of 3, 3 of 3 on the group header row (so I'm assigning a number of each CustomerId and seeing how many are on that Company)....
I have used the page breaks in the past for this but not possible this time around because I cannot break the pages. I have tried using RunningValue but not working so I'm lost here.
Header | Customer A 1 of 3
Details
Header | Customer B 2 of 3
Details
Header | Customer C 3 of 3
Details
Say I have data like this:
And a simple table with a Group based on Customer:
The expression I'm using in the group header row is:
="Customer " & Fields!Customer.Value & " ("
& RunningValue(Fields!Customer.Value, CountDistinct, Nothing)
& " of "
& CountDistinct(Fields!Customer.Value, "DataSet1") & ")"
Which is using a couple of aggregate functions and using these to create a longer string with the Customer detail.
You can see that using CountDistinct is the key here - it's used in RunningValue to get the group ranking and also as an aggregate expression by itself to get the total in the Dataset (where DataSet1 is the Dataset name).
Results look good:
You will of course need to tweak slightly for your field names and your exact formatting requirements.
I am trying to update a field inside one table, "Todays_Deliveries", from another table called "Current_Delivery". The field is a number field called "Remaining" which describes how many units there are of a particular item left on the daily deliveries.
The "Todays_Deliveries" table is generated using an APPEND query from another master table with every delivery stored in it. Everytime the user opens a delivery on a form anything in the "Current_Delivery" table is removed using a DELETE query and then generated based on the delivery selected using an APPEND query from the "Todays_Deliveries" table.
Both tables have identical fields and identical values, given one is generated from the data of the other.
I have tried to create an UPDATE query to update the "Todays_Deliveries" table when a user edits the "Current_Delivery" table but it doesn't work. I recieve no error messages the field just doesn't update. The steps I took were as follows:
Add both tables.
Change to UPDATE query.
Link tables using the Remaining field.
Set the Field: Remaining and
Set the Table: Current_Delivery.
Set Update To: [Todays_Deliveries].[Remaining].
Any advice/help would be greatly appreciated.
EDIT:
BEFORE:
Todays_Deliveries
ID Date Time Ref Studio Description Total Remaining
3187 23-Oct-12 10:00 3663 ROCK PINK 1900 1900
Current_Delivery
ID Date Time Ref Studio Description Total Remaining
3187 23-Oct-12 10:00 3663 ROCK PINK 1900 1000
AFTER:
Todays_Deliveries
ID Date Time Ref Studio Description Total Remaining
3187 23-Oct-12 10:00 3663 ROCK PINK 1900 1000
UPDATE:
I've got the query working using the below function
UPDATE Todays_Deliveries SET Remaining = DLookup("Remaining","Current_Delivery","[MP-Ref] = Form![MP-Ref] And [Cat No] ='" & [Cat No] & "'")
WHERE "[MP-Ref] = Form![MP-Ref] And [Cat No] ='" & [Cat No] & "'";
Where MP-Ref is the delivery reference that list a number of items, and Cat No is the individual item reference.
The only problem is the other items in the _Daily_Deliveries_ table, the ones not in the _Current_Delivery_ table, have there remaining field set to 0 when I run it. Is there anyway to stop this?
In MS Access I have a table like this:
TABLE USER
Id (int)
Status (text)
OldStatus (text)
I would like to create a MS Access Query which, when executed, moves the content of Status field to the top of OldStatus, and adds the current year. For example:
Before execution:
ID STATUS OLDSTATUS
1 Very good [2010] Excelent
[2009] Very bad
2 Excelent [2010] Bad
[2009] Good
After execution:
ID STATUS OLDSTATUS
1 [2011] Very good
[2010] Excelent
[2009] Very bad
2 [2011] Excelent
[2010] Bad
[2009] Good
How can I do that? THANK YOU!!
Didn't know the name of your table, so you'll have to substitute. The goal here is to maintain the old status while concatenating the current status. I used a space (" ") to put between, but you can use any character you want.
Update Status_Table
Set OLDSTATUS = OLDSTATUS & " " & STATUS
For what it is worth, there is a better way. Create a StatusHistory table:
StatusHistoryID
, StatusID
, Status
, Status_Date
You would have more flexibility here. Reports could be set for a date range or a particular year. You're table would be very hard to run a report on the status for 2010.