I've done this before, just a test as to whether a record already exists in a table before I insert a new record. This was basically what I did, yet this time I get an error
Error: "3061 Too few parameters. Expected 2." I tried to be very specific (tblfromICPMS.Woid instead of just Woid) thinking that might help, but it didn't really make a difference. I get the specifically at the line
If rs.RecordCount = 0 Then This is the code, where ThisWoid, Analyte and ThisTestId are local variables:
DIM rs As Object strSQL = "SELECT tblfromICPMS.Woid, tblfromICPMS.Analyte, tblfromICPMS.TestID FROM tblFROMICPMS WHERE (tblFROMICPMS.woid = " & ThisWoid & ") AND (tblFROMICPMS.analyte = " & Analyte & ") AND (tblfromICPMS.Testid=" & ThisTestID & ") " Set rs = CurrentDb.OpenRecordset(strSQL) If rs.RecordCount = 0 Then "insert record" End IF UPDATE: error message changed to 1 expected after updating sqlstr in comments, also included declaration of rs. For clarification tblFromICPMS is a table which contains the columns Woid, Analyte and TestId. I have retrieved three values and stored them in local variables ThisWoid, Analyte and ThisTestId. I want to insert a record but first I must see if it already exists in tblfromICPMS. Also ThisWoid and Analyte are strings
(tblFROMICPMS.woid = ThisWoid). What isThisWoid. Isn't it supposed to be(tblFROMICPMS.woid = " & ThisWoid & ")"?TabelfromICPMS.TestID. That should betblfromICPMS.TestIDinstead.SELECT tblfromICPMS.Woid, tblfromICPMS.Analyte, TabelfromICPMS.TestID FROM tblFROMICPMS WHERE (tblFROMICPMS.woid = ThisWoid) AND (tblFROMICPMS.analyte = Analyte) AND (tblfromICPMS.Testid=ThisTestID)where you want something like "WHERE (tblFromICPMS.woid = " & strVariable & ") AND " `"SELECT tblfromICPMS.Woid, tblfromICPMS.Analyte, tblfromICPMS.TestID FROM tblFROMICPMS WHERE (tblFROMICPMS.woid = " & ThisWoid & ") AND (tblFROMICPMS.analyte = " & Analyte & ") AND (tblfromICPMS.Testid=" & ThisTestID & ") "And also, if any of your conditions are compared to string you need a single quote on each side as"... ='" & var & "' and ..."