Try this..
if y is a number then
x = nz(dcount("YourPrimaryKeyField","YourTable","WhichEverField=" & y ) ,0)
if y is a string then
x = nz(dcount("YourPrimaryKeyField","YourTable","WhichEverField='" & y & "'" ) ,0)
or with no Where
x = nz(dcount("YourPrimaryKeyField","YourTable", ) ,0)