Parameter query Help

  • Thread starter Thread starter Mark A. Sam
  • Start date Start date
M

Mark A. Sam

What am I dong wrong? I want a Combo box, [FindSpecTemplate] to be the
parameter for the query. I get error "Too few parameters. Expected 1"

CurrentDb.Execute "Parameters [FindSpecTemplate] Long;" & _
"Delete [RuleHt Specs Template B].[rhSpecID]" & _
"FROM [RuleHt Specs Template B]" & _
"WHERE [RuleHt Specs Template
B].[rhSpecID]=[FindSpecTemplate];"

Thanks for the help and God Bless,

Mark A. Sam
 
Hello Sandra,

I get the same thing.

CurrentDb.Execute "Parameters [FindSpecTemplate] Long;" & _
"Delete [RuleHt Specs Template B].[rhSpecID]" & _
"FROM [RuleHt Specs Template B]" & _
"WHERE [RuleHt Specs Template B].[rhSpecID]= " &
Me.FindSpecTemplate & ";"

I also tried,
= " & Me.[FindSpecTemplate] & ";"
and
= " & Me![FindSpecTemplate] & ";"
and
and other various syntaxes, but with the same result.

I accidently did:
"WHERE [RuleHt Specs Template B].[rhSpecID]= ]" &
Me.FindSpecTemplate & ";"

Notice the left ] (bracket) after the = sign...
That gave me a syntax error:

Syntax error in query expression '[RuleHt Specs Template B].[rhSpecID]= ]10"

10 being the value in the combo. The combo is unbound but the column it is
pointing to is a long int.

This is Access XP in a A2000 Database.? I wonder if that could be a
problem? The other day I did a DLookup and Appended the value of a
Textbox, which didn't work. So I hardcoded it as above and it did work.



God Bless,

Mark



Sandra Daigle said:
Intead of declaring a parameter you need to append in the value of the
combo - the way you have it the name of the combo is hardcoded into the
string. I am assuming that rhSpecID is a numeric field, in which case the
following should work:

CurrentDb.Execute "Delete [RuleHt Specs Template B].[rhSpecID]" & _
"FROM [RuleHt Specs Template B]" & _
"WHERE [RuleHt Specs Template B].[rhSpecID]=" & me.FindSpecTemplate &
";"

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

What am I dong wrong? I want a Combo box, [FindSpecTemplate] to be
the parameter for the query. I get error "Too few parameters.
Expected 1"

CurrentDb.Execute "Parameters [FindSpecTemplate] Long;" & _
"Delete [RuleHt Specs Template B].[rhSpecID]" & _
"FROM [RuleHt Specs Template B]" & _
"WHERE [RuleHt Specs Template
B].[rhSpecID]=[FindSpecTemplate];"

Thanks for the help and God Bless,

Mark A. Sam
 
Hi,

I think you missed the point of Sandra's post : read her syntax again,
you'll notice that she doesn't use parameters in the SQL-string.

Dirk

Mark A. Sam said:
Hello Sandra,

I get the same thing.

CurrentDb.Execute "Parameters [FindSpecTemplate] Long;" & _
"Delete [RuleHt Specs Template B].[rhSpecID]" & _
"FROM [RuleHt Specs Template B]" & _
"WHERE [RuleHt Specs Template B].[rhSpecID]= " &
Me.FindSpecTemplate & ";"

I also tried,
= " & Me.[FindSpecTemplate] & ";"
and
= " & Me![FindSpecTemplate] & ";"
and
and other various syntaxes, but with the same result.

I accidently did:
"WHERE [RuleHt Specs Template B].[rhSpecID]= ]" &
Me.FindSpecTemplate & ";"

Notice the left ] (bracket) after the = sign...
That gave me a syntax error:

Syntax error in query expression '[RuleHt Specs Template B].[rhSpecID]= ]10"

10 being the value in the combo. The combo is unbound but the column it is
pointing to is a long int.

This is Access XP in a A2000 Database.? I wonder if that could be a
problem? The other day I did a DLookup and Appended the value of a
Textbox, which didn't work. So I hardcoded it as above and it did work.



God Bless,

Mark



Sandra Daigle said:
Intead of declaring a parameter you need to append in the value of the
combo - the way you have it the name of the combo is hardcoded into the
string. I am assuming that rhSpecID is a numeric field, in which case the
following should work:

CurrentDb.Execute "Delete [RuleHt Specs Template B].[rhSpecID]" & _
"FROM [RuleHt Specs Template B]" & _
"WHERE [RuleHt Specs Template B].[rhSpecID]=" &
me.FindSpecTemplate
&
";"

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

What am I dong wrong? I want a Combo box, [FindSpecTemplate] to be
the parameter for the query. I get error "Too few parameters.
Expected 1"

CurrentDb.Execute "Parameters [FindSpecTemplate] Long;" & _
"Delete [RuleHt Specs Template B].[rhSpecID]" & _
"FROM [RuleHt Specs Template B]" & _
"WHERE [RuleHt Specs Template
B].[rhSpecID]=[FindSpecTemplate];"

Thanks for the help and God Bless,

Mark A. Sam
 
Thank you Sandra,

I have done a lot of goofy workarounds over the years because I saw no
examples anywhere of running a query string from Code. The only examples I
saw were from microsoft and involved Parameters and the explanation was not
understandable to me.

God Bless,

Mark


Sandra Daigle said:
In your case it was unneeded since you are appending the test value into the
actual SQL string.

A query parameter is used when a the test value is unknown when a query is
saved. Access doesn't require you to declare a parameter, instead it treats
anything that can't be resolved as a field name as a parameter. For example,
if I have a Customer table with fields Custid, CustName and Address1, but no
field named 'CustRating' and I write and save the following query, Access
will treat 'CustRating' as a parameter and will prompt you for its value. I
believe that other DBMS are more restrictive and require you explicitly
declare parameters.

Select Custid, Custname, Address1, CustRating from Customers

In Access/Jet, the parameter declaration is useful when you need to ensure
that the value supplied to the parameter is a specific datatype.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Thanks Dirk,
You are correct. I removed the parameters declaration and it worked.
I never did and still don't understand the Parameters declaration.

God Bless,

Mark

Dirk Maes said:
Hi,

I think you missed the point of Sandra's post : read her syntax
again, you'll notice that she doesn't use parameters in the
SQL-string.

Dirk

Hello Sandra,

I get the same thing.

CurrentDb.Execute "Parameters [FindSpecTemplate] Long;" & _
"Delete [RuleHt Specs Template B].[rhSpecID]" & _
"FROM [RuleHt Specs Template B]" & _
"WHERE [RuleHt Specs Template B].[rhSpecID]= " &
Me.FindSpecTemplate & ";"

I also tried,
= " & Me.[FindSpecTemplate] & ";"
and
= " & Me![FindSpecTemplate] & ";"
and
and other various syntaxes, but with the same result.

I accidently did:
"WHERE [RuleHt Specs Template B].[rhSpecID]= ]" &
Me.FindSpecTemplate & ";"

Notice the left ] (bracket) after the = sign...
That gave me a syntax error:

Syntax error in query expression '[RuleHt Specs Template
B].[rhSpecID]= ]10"

10 being the value in the combo. The combo is unbound but the
column it is pointing to is a long int.

This is Access XP in a A2000 Database.? I wonder if that could be a
problem? The other day I did a DLookup and Appended the value of a
Textbox, which didn't work. So I hardcoded it as above and it did
work.



God Bless,

Mark



Intead of declaring a parameter you need to append in the value of
the combo - the way you have it the name of the combo is hardcoded
into the string. I am assuming that rhSpecID is a numeric field,
in which case the following should work:

CurrentDb.Execute "Delete [RuleHt Specs Template B].[rhSpecID]" & _
"FROM [RuleHt Specs Template B]" & _
"WHERE [RuleHt Specs Template B].[rhSpecID]=" &
me.FindSpecTemplate & ";"

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this
newsgroup.


Mark A. Sam wrote:
What am I dong wrong? I want a Combo box, [FindSpecTemplate] to
be the parameter for the query. I get error "Too few parameters.
Expected 1"

CurrentDb.Execute "Parameters [FindSpecTemplate] Long;" & _
"Delete [RuleHt Specs Template B].[rhSpecID]" &
_ "FROM [RuleHt Specs Template B]" & _
"WHERE [RuleHt Specs Template
B].[rhSpecID]=[FindSpecTemplate];"

Thanks for the help and God Bless,

Mark A. Sam
 
Back
Top