Notiophilus
Registered User.
- Local time
- Today, 12:29
- Joined
- Jan 18, 2015
- Messages
- 42
I have a list of authors, each of which may go by multiple pseudonyms. One of these is the "main" pseudonym and is displayed in forms, reports etc. (E.g. "JRR Tolkien" is the main pseud, synonymous to "John Ronald Reuel Tolkien" and "hobbitlover1")
When I want to add a completely new author, by entering a new pseudonym into a form (=strNewPseud) I do the following:
It works perfectly well, but I can't help second-guessing myself. Is this really the most efficient approach?
- tblAuthor: AuthorID [PK, autogenerated], MainPseudID
- tblPseud: PseudID [PK, autogenerated], Pseud [text], AuthorID
When I want to add a completely new author, by entering a new pseudonym into a form (=strNewPseud) I do the following:
Code:
' 1) add new pseud (text), get autogenerated PseudID
strSQL = "INSERT INTO tblPseud (Pseud)" & _
" VALUES ('" & strNewPseud & "');"
DBEngine(0)(0).Execute strSQL, dbFailOnError
' 2) insert that PseudID as the main pseud into tblAuthor, get autogenerated AuthorID
lngNewPseudID = ELookup("[PseudID]", "tblPseud", "Pseud = '" & strNewPseud& "'")
strSQL = "INSERT INTO tblAuthor ( MainPseudID )" & _
" VALUES (" & strNewPseud & ");"
DBEngine(0)(0).Execute strSQL, dbFailOnError
' 3) find that new AuthorID, then update tblPseud with the AuthorID we just got.
lngNewAuthorID = ELookup("[AuthorID]", "tblAuthor", "[MainPseudID] = " & lngNewPseudID)
strSQL = "UPDATE tblPseud" & _
" SET tblPseud.AuthorID = " & lngNewAuthorID & _
" WHERE tblPseud.PseudID = " & strNewPseudID & ";"
DBEngine(0)(0).Execute strSQL, dbFailOnError
It works perfectly well, but I can't help second-guessing myself. Is this really the most efficient approach?