I don't know where to post this feedback (Access or VBA), so may be a moderator will move it to the proper forum. I didn't find much information on Internet about my subject; or should I better say that I'm just a newbie who doesn't understand complex codes to do the same. I can copy and paste them however, but it's quite important to know what I'm typing in order to avoid malicious code. I also strive to make things as easy and intuitive as possible, for a better understanding and teaching.
So finally I want to share my solution when it comes to append records from a form onto related tables. Suppose that you have a primary table that have to feed a foreign one. Record source for combo boxes comes from primary tables and you need to insert values typed in combo boxes both to primary and foreign related fields. You can violate key rules because Access can't refresh data without the appropriate code, which was my concern. So here is my method to overcome this.
Code: Select all
Private Sub cmdAppend_Click()
Person
CurrentDb.Execute (" INSERT INTO Person (id, prefix_title, first_name, middle_name, last_name, suffix_title, signature, gender) " _
& " VALUES ('" & Me.cboIdentityCard & "', '" & Me.cboPrefix & "', '" & Me.cboFirstName & "', '" & Me.cboMiddleName & "', '" & Me.cboLastName & "', '" & Me.cboSuffix & "', '" & Me.txtSignature & "', '" & Me.cboGender & "');")
End Sub
Private Function Person()
If IsNull(DLookup("chrIdentityCard", "tblIdentityCard", "[chrIdentityCard] = '" & Me.cboIdentityCard & "'")) Then
CurrentDb.Execute (" INSERT INTO tblIdentityCard (chrIdentityCard) VALUES ('" & Me.cboIdentityCard & "');")
End If
If IsNull(DLookup("chrGivenName", "tblGivenName ", "[chrGivenName] = '" & Me.cboFirstName & "'")) Then
CurrentDb.Execute (" INSERT INTO tblGivenName (chrGivenName) VALUES ('" & Me.cboFirstName & "');")
End If
If IsNull(DLookup("chrSurname", "tblSurname ", "[chrSurname] = '" & Me.cboMiddleName & "'")) Then
CurrentDb.Execute (" INSERT INTO tblSurname (chrSurname) VALUES ('" & Me.cboMiddleName & "');")
End If
If IsNull(DLookup("chrSurname", "tblSurname ", "[chrSurname] = '" & Me.cboLastName & "'")) Then
CurrentDb.Execute (" INSERT INTO tblSurname (chrSurname) VALUES ('" & Me.cboLastName & "');")
End If
End Function
Carlos.