G
Guest
I have the following SQL commands run by a command button on a form. What i'm trying to do is add a user to my database in two different tables. The first table, Candidates, has personal data. The second table, Web, has CID (should be copied from Candidates table), UserName, and Password
In the Candidates table, CID is autogenerated. The first SQL command does this properly. What I'm having trouble with is inserting into the web table. The web table has a primary key of CID, but it's just a number field. When I run these commands, i get a primary key violation for the second SQL command
Ideally, the second SQL command should do this
Assume CID in Candidates is 9999, then Web should hold the values 9999, c9999, 9iO0REab (or whatever random password it comes up with
AddC just simply takes the CID and puts a "c" in front of it. RandomPassword generates a random password
Dim SQL As Strin
SQL = "Insert into candidates (firstname, middlename, lastname, suffix, street, city, state, zip, homephone, cell, email, coname, costreet, cocity, costate, cozip, cophone, fax, school1, dategraduated1, degree1, major1, school2, dategraduated2, degree2, major2, memo) values (txtFirstName, txtMiddleName, txtLastName, txtSuffix, txtStreet, txtCity, txtState, txtZIP, txtPhone, txtCell, txtEmail, txtCoName, txtCoStreet, txtCocity, txtCoState, txtCoZIP, txtCoPhone, txtFax, txtSchool1, txtGrad1, txtDegree1, txtMajor1, txtSchool2, txtGrad2, txtDegree2, txtMajor2, txtMemo);
DoCmd.RunSQL SQ
Dim sql2 As Strin
sql2 = "insert into web (CID, UserName, Password) values ([CID], AddC([CID]), RandomPassword());
DoCmd.RunSQL sql2
In the Candidates table, CID is autogenerated. The first SQL command does this properly. What I'm having trouble with is inserting into the web table. The web table has a primary key of CID, but it's just a number field. When I run these commands, i get a primary key violation for the second SQL command
Ideally, the second SQL command should do this
Assume CID in Candidates is 9999, then Web should hold the values 9999, c9999, 9iO0REab (or whatever random password it comes up with
AddC just simply takes the CID and puts a "c" in front of it. RandomPassword generates a random password
Dim SQL As Strin
SQL = "Insert into candidates (firstname, middlename, lastname, suffix, street, city, state, zip, homephone, cell, email, coname, costreet, cocity, costate, cozip, cophone, fax, school1, dategraduated1, degree1, major1, school2, dategraduated2, degree2, major2, memo) values (txtFirstName, txtMiddleName, txtLastName, txtSuffix, txtStreet, txtCity, txtState, txtZIP, txtPhone, txtCell, txtEmail, txtCoName, txtCoStreet, txtCocity, txtCoState, txtCoZIP, txtCoPhone, txtFax, txtSchool1, txtGrad1, txtDegree1, txtMajor1, txtSchool2, txtGrad2, txtDegree2, txtMajor2, txtMemo);
DoCmd.RunSQL SQ
Dim sql2 As Strin
sql2 = "insert into web (CID, UserName, Password) values ([CID], AddC([CID]), RandomPassword());
DoCmd.RunSQL sql2