With this code:
Set col = db.Search(\"Form=\"\"formname\"\" & id=212\", time, 0)
I explicity give the search function 212 for example, but
Set col = db.Search("Form=""formname"" & id=" + Cstr(val), time, 0)
should work.
Cstr() converts the integer value to a string.