I have a query in access that is suppose to check whether the item already exists in the database before inserting it:
INSERT INTO FinalizedPrintedStickers
Values('0000846043-481-9-0',
'48IG - 1F Straight Panel ',
'481 ',
'0',
'0',
'',
'210',
'Printed')
WHERE NOT EXISTS(SELECT [SN] FROM FinalizedPrintedStickers Where SN = '0000846043-481-9-0')
Now, I've gotten this error before but usually it's when there's no table for example if you "select * from test table" and you type "Select *" and leave out the from clause you get the same error. But I have a table ? Perhaps my where not exists syntax is wrong?
Edit:
Ok, I've added a table "Dual" as suggested with code copy pasted from this question : Table-less UNION query in MS Access (Jet/ACE)
Attempting to add a constraint as shown gave me this error :
after i press ok it highlights the word "Check"
I've never really dealt with constraints (in access atleast..) my syntax is probably wrong
Edit 2:
Adding constraints using ctrl G command
And when I press enter...
Adding constraints using ADO:
And when i press run...
ALTER TABLE
from ADO. UseCurrentProject.Connection.Execute
– FaustinaCreateDualTable()
routine that @Faustina put in his answer. – CurlyCreateDualTable
procedure, you can execute that statement with ADO in Access by opening the Immediate window (Ctrl+g), pasting the text from the next comment as a single line, and pressing enter to execute it. – FaustinaCurrentProject.Connection.Execute "ALTER TABLE Dual ADD CONSTRAINT there_can_be_only_one CHECK ((SELECT Count(*) FROM Dual) = 1);"
– Faustina