vba - Error: too few Parameters. Expected 3...while executing SQL statement in Access -


i've done before, test whether record exists in table before insert new record. did, yet time error

error: "3061 few parameters. expected 2." 

i tried specific (tblfromicpms.woid instead of woid) thinking might help, didn't make difference. @ line

if rs.recordcount = 0 

this code, thiswoid, analyte , thistestid local variables:

dim rs object strsql = "select tblfromicpms.woid, tblfromicpms.analyte, tblfromicpms.testid tblfromicpms (tblfromicpms.woid = " & thiswoid & ") , (tblfromicpms.analyte = " & analyte & ") , (tblfromicpms.testid=" & thistestid & ") " set rs = currentdb.openrecordset(strsql) if rs.recordcount = 0    "insert record" end if  

update: error message changed 1 expected after updating sqlstr in comments, included declaration of rs. clarification tblfromicpms table contains columns woid, analyte , testid. have retrieved 3 values , stored them in local variables thiswoid, analyte , thistestid. want insert record first must see if exists in tblfromicpms. thiswoid , analyte strings

first of all, i'd try diming rs recordset, not object. also, stick in message box make sure sql string makes sense:

dim rs recordset strsql = "select woid, analyte, testid tblfromicpms (woid = " & thiswoid & ") , (analyte = " & analyte & ") , (testid=" & thistestid & ") " msgbox strsql set rs = currentdb.openrecordset(strsql) if rs.recordcount = 0    "insert record" end if  

see if message box results give clues what's wrong. typically, error happens when access doesn't understand 1 of variables.

don't forget, text needs surrounded single quotes in sql string, integers not.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -