Created
June 10, 2013 14:51
-
-
Save janikvonrotz/5749333 to your computer and use it in GitHub Desktop.
MSAccess: Update Foreign Key
#VisualBasic
#MSAccess
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Public Sub ListVerweisAktualisieren(ListControl As Control, TableName As String, TableLinkName As String, Values As Variant, IDDataSet As String, IDDataSetName As String, LinkDataSetName As String) | |
| Dim db As DAO.Database | |
| Set db = CurrentDb | |
| Dim AnzahlItems As Integer | |
| AnzahlItems = ListControl.ListCount | |
| Dim ValueIndex As Integer | |
| ValueIndex = 0 | |
| 'Delete of all Register data in link table | |
| db.Execute "DELETE * FROM " & TableLinkName & " WHERE " & IDDataSetName & " = " & IDDataSet, dbFailOnError | |
| For x = 0 To AnzahlItems - 1 | |
| If ListControl.Selected(x) = True Then | |
| 'Link the Register to the selected value | |
| db.Execute "INSERT INTO " & TableLinkName & " (" & IDDataSetName & "," & LinkDataSetName & " ) VALUES(" & IDDataSet & ", " & Values(ValueIndex) & ")" | |
| ValueIndex = ValueIndex + 1 | |
| End If | |
| Next x | |
| End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment