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.
Related
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?
I have a table in Access that I use as a progress tracker/to do list, with one field containing the date (short text) and what I did that day (long text). An example would be like this
date | progress
----------------
6/20 | did item1
| tomorrow do item2 and item3
6/21 | long text I continue in the next line for visibilty
| continued
| to do tomorrow
6/22 | item6 completed
etc. I enter these things manually. the past 3 weeks or so that I have been updating this table, it opens in the same order every time -- the order in which I created the records. Recently, the table opened in a completely random order, and continues to open in that new order.
I know now that it would have been good to create an autonumber field and order it by that, or have the date field's default value =Now(). I ahve far to many fields to make a new ID field and manually number each record in the order I created them.
Is it at all possible to force the table to order the records in either the order I created the records, or at least the previous configuration (which was just ordered by the time created)?
Also, is there a better way to be doing this...? I want to just have a record for other people who will work with this in the future. In addition, I am new to SQL, and the Access SQl has weird/unique ways of doing things, so for some queries I know I may need in the future I keep a table with the query name and some documentation for what exactly it does and some notes about the syntax (the SQL editor does not allow for -- comments). Is there a better way to do this, too?
Thanks for any help!
one field containing the date (short text)
Dates should never be stored as anything else than date values. No exceptions.
So change the data type of the field to Date, sort on this, and your troubles are gone.
To order Null dates last:
Order By Abs([DateField] Is Null), [DateField]
I am trying to create a data set which associates the correct marketing channel with a certain completed application and am having a VERY hard time figuring out the best way to do it.
I have 3 tables:
Table#1: Contact Info;
Table#2: Application Info;
Table#3: Channel Tracking History Info
The relevant fields in the tables referenced above are:
Table#1: ID_table_1
Table#2: ID_Table_1 , Application_Created_Date_Time_Tbl_2
Table#3: ID_Table_1 , Channel_Update_Created_Date_Time_Tbl_3 , Channel_Tracking_info
(Note: all 3 tables are joined on ID_Table_1 column)
Table#1 is where the persons personal information is stored along with the last marketing channel they visited our site from. My problem is I need to know which channel they came in from when the completed an application, Table#2. In order to do that I need to select the record from Table#3 that has a "created date time" closest to the application "created date time" with out being after.
Note: Table#1 has the ID which matches the records back to Table#3. So, I have to join Table#2 to Table#1 then pick the record in Table#3 which is closest in date time to the created date time in Table#2.
In example:
Table #2 - Record #1 - Created Date time # 11/24/15 10:30:14
Table #3 - Record #1 - Created Date time # 11/24/15 10:29:10
Table #3 - Record #2 - Created Date time # 11/24/15 10:29:16
Table #3 - Record #3 - Created Date time # 11/24/15 10:31:15
I want to join only Table#3 - Record#2 to Table#2 - Record#1. I want this record because it is the closest to the created date time in Table#2.
Also note, I need to use views when possible so others can use this data and not have to rely on me sending them updated code when updates occur.
I hope this makes sense, if not please ask me and I will help answer any more questions! I HAVE to get this done or my boss is going to be very disappointed in my skill level. He is not happy it has taken me this long to figure it out (2 days of running in circles). :-\
-Thanks ahead of time,
The guy less skilled than you
try something on the lines of below structure, you will need to change it to use date differences and add the 3rd table as well..
select *
from test1
,test2
where test1.a = test2.a
and (test1.b - test2.c) = (
select min(t1.b - t2.c)
from test1 t1
,test2 t2
where t1.a = t2.a
and test1.a = t1.a)
I want to create sequence number in my order form that after save button it generate a Order No in Order No field of table, as I m not much knowledge in VBA but got from internet some codes which i try to implement but its not working
The code is given below please see reply if there is any edit or where i m mistaked
Table:
ID | date | party Name | Order No| Item | qty | Rate | Amount |
Private Sub save_Click()
If Me.orderno = Null Then
Me.orderno = Nz(DMax([Order No], Order), 0) + 1
End If
End Sub
If the name of the table is 'Order', the following should work:
If IsNull(Me.orderno) Then
Me.orderno = Nz(DMax("[Order No]", "Order"), 0) + 1
End If
A few other comments:
Date is a reserved word and should not be used as a field name, so best to change it to avoid problems. http://office.microsoft.com/en-us/access-help/access-2007-reserved-words-and-symbols-HA010030643.aspx
It is also poor practice to use spaces in field names.
The problems here were quite obvious, however, for future reference, you should state what error you are receiving and which line it occurs on. 'Not working' does not provide any clues.
Add the line
DoCmd.RunCommand acCmdSaveRecord
at the end, to insure that the record is saved.
Make sure that the code is actually running and that orderno is bound to the field orderno.
If it still doesn't appear to work, step through he code to see what is happening.
As for the comment about autonumber, and autonumber is fine if you don't care about gaps in the numbering sequence, which will eventually occur using an autonumber.
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?