I am in the process of renormalizing an Access 2010 database while trying to not lose any data. I know you have all been there! They used [Client].[case] to store a case number for a period of time and then delete it the next year. This would then have the effect of "forgetting" the client ever had a service. So..
I have a database for casework.
A new table:
/ClientHistory/
[ClientHistory].[ID] - autonumber PK
[ClientHistory].[[ClientSSN] -Int FK
[ClientHistory].[ServiceID] - Int FK
[ClientHistory].[ServiceDate] -Date
and
/Client/
[Client].[SSN] -Int PK
[Client].[Case] -Int
[Client].[ClientName]
etc.
I want to select all records from [Client] where [Client].[Case] is not null and then
for each record in the recordset create a new record in the [Client History] table using the FK [SSN]
Setting :
[Client].[SSN] = Recordset[SSN], [ClientHistory].[ServiceID] = 1, [ClientHistory].[ServiceDate] = #12/30/2012#
Since I am making new records in an existing table it has to be an append query right? But all the tutorial for append don't seem to show you able to do this for each record in a Query. (sorry I used to do this with VB on .ASP pages. I'd be doing this in a loop. Working direct in access is still difficult for me)
or should it be an update query like:
UPDATE [Clients] INNER JOIN [Clients] ON [Clients].SSN = [Clients History].SSN SET [Clients History].SSN = [Clients].[SSN], [Clients History].AgencyID = 1, [Clients History].SERVICEID = 28, [Clients History].DATESERV = #12/30/2012#
WHERE ((([Clients].CASE) Is Not Null));
but this doesn't look right because it is assuming that there must be records with the SSN in the ClientsHistory table and there might not be. This might be the first one...
Please put me back on the right track.
I have a database for casework.
A new table:
/ClientHistory/
[ClientHistory].[ID] - autonumber PK
[ClientHistory].[[ClientSSN] -Int FK
[ClientHistory].[ServiceID] - Int FK
[ClientHistory].[ServiceDate] -Date
and
/Client/
[Client].[SSN] -Int PK
[Client].[Case] -Int
[Client].[ClientName]
etc.
I want to select all records from [Client] where [Client].[Case] is not null and then
for each record in the recordset create a new record in the [Client History] table using the FK [SSN]
Setting :
[Client].[SSN] = Recordset[SSN], [ClientHistory].[ServiceID] = 1, [ClientHistory].[ServiceDate] = #12/30/2012#
Since I am making new records in an existing table it has to be an append query right? But all the tutorial for append don't seem to show you able to do this for each record in a Query. (sorry I used to do this with VB on .ASP pages. I'd be doing this in a loop. Working direct in access is still difficult for me)
or should it be an update query like:
UPDATE [Clients] INNER JOIN [Clients] ON [Clients].SSN = [Clients History].SSN SET [Clients History].SSN = [Clients].[SSN], [Clients History].AgencyID = 1, [Clients History].SERVICEID = 28, [Clients History].DATESERV = #12/30/2012#
WHERE ((([Clients].CASE) Is Not Null));
but this doesn't look right because it is assuming that there must be records with the SSN in the ClientsHistory table and there might not be. This might be the first one...
Please put me back on the right track.