SCHNYDES
I am puzzled -- updating your primary key??
Try this "from the trenches"...
Often when designing a financial application, the programmer will use the G/L account as the primary key. Occasionally, a G/L account number has to be changed. This results in writing a routine (before 4GL and relational databases were around) to go through all the transactions, balance files, etc and renumber the account number. If several G/L accounts were being renumbered, this process would take a long time. Very messy.
Although using the G/L account number as the primary key seems to make sense, my belief is that if there is a chance the primary key needs to be changed don't use it as a primary key. (Rick's rule???)
It took me two years to convince the senior programmer to use a sequential index number (or autonumber) as the primary key, and use the G/L account number as a desciption field. Worked like a charm, and renumbering accounts became a piece of cake. Change the account number in the G/L master file and all the transactions depicted the change.
Does this scenario fit??
Next, you seem well versed with Access. But I will ask the question anyway. If you are using the query design view to create and run your queries, have you changed the query to an update query? Depends on the verson of Access, but if you click on query header / title bar in design view -- select "query type", and switch to update. The criteria will change a bit. Fill in an examples for "update to" and "criteria". Now switch to the SQL view. Copy the SQL statement into the clip board.
Now go to your form. Add a command button. On the "on click" event property for the command button, go to the VB code editor. Paste your update query. (You may get syntax errors -- don't worry.)
Now look at the update query. Basically, we want to replace the "update to" and "criteria" examples with variables.
Here is where is gets a little more tricky. Quotes and variables. For simplicity, I am going to assign the query to a string.
I am assuming...
me.fld_pk_name
is the primary key for the form. You have changed the primary key from the old view to the new view, but not updated it. We are going to take advantage of the .old property used by Access to store the old value of course. (Every wonder how Access could "undo" a change by hitting the escape key?)
dim strSQL as string
strSQL = "select your_table set your_table.fld_pk_name = " & me.fld_pk_name & " where your.fld_pk_name = " & me.fld_pk_name.old
Note...
How the text of the select statemnt is within quotes, and the the field name variables are variable names are concatinated to the string using "&".
Note...
Spaces after "=" sign, and before the "where". Otherwise you may get a syntax error when executing the code.
Note...
If your primary key is a text string, we need to put quotes around the vairable. There are variations of how to do this. This is my preferred way...
dim strSQL as string, strQ as string
strQ = chr$(34)
strSQL = "select ... = " & strQ & me.fld_pk_name & strQ & " where ... = " & strQ & me.fld_pk_name.old & strQ
'Now execute the query, add this after defining the SQL string
docmd.runsql strSQL
If you have more than one query to run, repeat the process of creating strSQL and running the command.
Lastly, back up your database before doing this. It sounds like you are updating the primary key, and need to update the associate foreign keys. If this process is messed up, you will loose the relationship with between the tables for this record.
Hey, did you just write some vb code? See it is not so bad.
As an alternative solution,
I suggest you consider using an autonumber for the primary key. Piece of cake -- Access will renumber all records after you reassign the primary key. Then create a new foreign key in your other tables. Run an update SQL statement to update the new foreign key in the related tables. Since you still have the old foreign key still in the table, this should be fairly easy too. (And you have a back out plan). Modify tables and reports as required to use th enew foreign key. If confident with the results, you can then delete old foreign key.
Richard