Hi,
I have a procedure to check itemName if it is exist in a table called tblItem. If it does exist, then set its ID to variable X, if not, then create that new item. I have two codes that roughly do the job, but performance-wise, which one is better?
code 1 : Using dlookup
code 2 : Using Recordset
The reason I consider using Recordset is that the performance is fast (CMIIW).
any input? Thanks
**the codes above are just rough codes, so pardon me if some variables are not defined first or some syntax errors exist
I have a procedure to check itemName if it is exist in a table called tblItem. If it does exist, then set its ID to variable X, if not, then create that new item. I have two codes that roughly do the job, but performance-wise, which one is better?
code 1 : Using dlookup
Code:
dim check as string
dim X as long
check=dlookup("ID","TblItem","ItemName='" & itemName & "'")
if isnull(check) then
'create new item
else
X=check
end if
code 2 : Using Recordset
Code:
dim dbs as database
dim rst as DAO.Recordset
dim qry as string
dim X as long
set dbs=currentDb
qry="SELECT * FROM TblItem WHERE ItemName='" & itemName & "'"
set rst=dbs.OpenRecordset(qry)
if rst.EOF=false then
X=rst("ID")
else
'create new item
end if
The reason I consider using Recordset is that the performance is fast (CMIIW).
any input? Thanks
**the codes above are just rough codes, so pardon me if some variables are not defined first or some syntax errors exist