Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Key Violation on SQL Insert -- Makes No Sense!

Status
Not open for further replies.

valerie

MIS
Dec 12, 2000
2
CA
I am trying to insert data into a table based on user input into a combo box (whenever the user types in something not in the list, it adds that value to the underlying table), using the following SQL syntax:

INSERT INTO TableName (PrimaryKey)
VALUES ([Forms]![Formname]!cmbComboBoxName);

Whenever I run it, I get a primary key violation--but if I replace ([Forms]![Formname]!cmbComboBoxName) with the same value that is in the box (in quoation marks), it works fine. A select statement works correctly using ([Forms]![Formname]!cmbComboBoxName)--but if I remove the key restriction from the table, the insert statement inserts blank records--so evidently the problem is with referencing the combo box text.

Any assistance would be greatly appreciated.
 
After a week--once I post a message, I figure it out.

For some reason, the SELECT works with just the command name, but for the INSERT one needs to use Forms!FormName!CommandName.Text.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top