Search code examples
sqlms-accessms-office

Copying Primary key to another field in Access


Hey, I'm struggling to copy the Primary Key to another field in Access. This is irrelevant , but clarifying on what I'm comparing.

... WHERE Tunniste=" & [Tarkiste] & ""

Tunniste = Primary Key , Autonumber , ID (Generated by Access.)

Tarkiste = This is the field I want to copy it to compare it.

I'm open to suggestions, I've already try'ed with Form_Load, using the following code.

Private Sub Form_Load()

DoCmd.RunSQL "UPDATE Korut SET [Tarkiste]=('" & Tunniste & "');"

End Sub

But this copied the same key to all the entries in "Tarkiste" field.

In simplicity I want 1:1 copy of field "Tunniste" to "Tarkiste" , whichever method it takes.

Started from this question. File Picker Replaces All Rows With The Same Choice.


Solution

  • If the two fields are in the same table, you can do this:

    DoCmd.RunSQL "UPDATE Korut SET [Tarkiste]=[Tunniste]"
    

    And its sure that it runs!