I used to know the answer to this, but it's been too long since I've
worked with recordsets. So anyway...
I'm trying to create a recordset that isolates a specific record (in
this case, an image file name) using a DAO recordset. The select
criteria are based on fields in an unbound form PhotoData. To
accommodate a few odd variations & formats, I've written the select
strings as follows:
strSelect = "SELECT Images.ImageFile, Images.Description " _
& "FROM Images " _
& "WHERE (ImageFile = Forms!PhotoData!txtPrefix "
strSelect = strSelect & strSpace & strSequence & ")"
For a particular record, that should resolve to the filename "Kirkley
002". To check my work in progress, I have a text box on the form
that receives the string generated by the select string. That string
reads:
SELECT Images.ImageFile, Images.Description FROM Images WHERE
(ImageFile = Forms!PhotoData!txtPrefix &' '&'00'&'2')
In that string, the Forms!PhotoData!txtPrefix should equal "Kirkley"
with the concatenation adding a space and the sequence value " 002".
I've set it up to create a query, and it seems to work fine in that
method, but in trying to open a recordset using:
Set rst1 = db1.OpenRecordset(strSelect, dbOpenDynaset)
I'm getting an error "Too few parameters. Expected 1." From all I've
done so far, I surmise the problem is with the Forms!PhotoData!
txtPrefix portion. What am I doing wrong with the syntax here?
TIA
Joe F.
storrboy - 20 Mar 2007 17:22 GMT
You need to reference the form the same as you did the variables.
strSelect = "SELECT Images.ImageFile, Images.Description " _
& "FROM Images " _
& "WHERE (ImageFile = '" & Forms!PhotoData!txtPrefix & "'"
strSelect = strSelect & strSpace & strSequence & ")"
Also, you didn't mention how strSpace and strSequence are assigned a
value, but they don't look like they're formated properly either. I'm
not sure what their actual values are supposed to be so I can't
comment on them.
rb608 - 20 Mar 2007 17:43 GMT
> You need to reference the form the same as you did the variables.
>
[quoted text clipped - 5 lines]
> Also, you didn't mention how strSpace and strSequence are assigned a
> value, but they don't look like they're formated properly either.
D'oh! Thanks. I hadn't been able to get my brain around the syntax;
but your post filled in the piece I'd been missing. I'm good now.
Tx again.
Joe F.