Re: dbs.Execute strSQL error - Too few parameters
- From: HeislerKurt@xxxxxxxxx
- Date: Thu, 21 Jun 2007 14:03:36 -0000
Thanks for the explanation. I rewrote the code and now get a "Too few
parameters. Expected 1."
This is the code:
strSQl = "UPDATE tblReferrals " & _
"INNER JOIN tblVictimReferral " & _
"ON tblReferrals.ReferralID =
tblVictimReferral.ReferralID " & _
"SET tblVictimReferral.VicRef_Relation2 = " & [Forms]!
[frmVictimReferral]![VicRef_Relation2] & " " & _
"WHERE (((tblReferrals.ReferralID)=" & [Forms]!
[frmVictimReferral]![ReferralID] & "));"
(Adding a space between the "...ReferrallID)=" and the ' " ' in the
WHERE clause didn't fix things.)
And this is what Debug spits out:
UPDATE tblReferrals INNER JOIN tblVictimReferral ON
tblReferrals.ReferralID = tblVictimReferral.ReferralID SET
tblVictimReferral.VicRef_Relation2 = Parent WHERE
(((tblReferrals.ReferralID)=2324));
###
I can't detect the syntax problem. Any ideas?
On Jun 21, 9:23 am, "Rick Brandt" <rickbran...@xxxxxxxxxxx> wrote:
HeislerK...@xxxxxxxxx wrote:
I'm getting the infamous error, "Too few parameters. Expected 2", when
executing an update SQL statement in VBA. I assume it's a SQL syntax
issue, but I can't find the problem, and I used a VBA generator to
generate the SQL statement.
Debugging points to this line:
dbs.Execute strSQl, dbFailOnError
Here's the code:
###
Dim dbs As DAO.Database
Set dbs = CurrentDb()
Dim strSQl As String
strSQl = "UPDATE tblReferrals " & _
"INNER JOIN tblVictimReferral " & _
"ON tblReferrals.ReferralID =
tblVictimReferral.ReferralID " & _
"SET tblVictimReferral.VicRef_Relation2 = [Forms]!
[frmVictimReferral]![VicRef_Relation2] " & _
"WHERE (((tblReferrals.ReferralID)=[Forms]!
[frmVictimReferral]![ReferralID]));"
Debug.Print strSQl
dbs.Execute strSQl, dbFailOnError
###
The Debug.Print spits this out:
UPDATE tblReferrals INNER JOIN tblVictimReferral ON
tblReferrals.ReferralID = tblVictimReferral.ReferralID SET
tblVictimReferral.VicRef_Relation2 = [Forms]![frmVictimReferral]!
[VicRef_Relation2] WHERE (((tblReferrals.ReferralID)=[Forms]!
[frmVictimReferral]![ReferralID]));
I tried removing the ";" at the end but the problem persists. Any
ideas? I'm about to stab myself in the eyes.
Thank you!
Kurt
SQL executed with Execute goes straight to Jet without the advantage of the
expression service like queries run from Access. The expression service is
what translates form references so when using Execute you cannot use
[Forms]![frmVictimReferral]! [VicRef_Relation2] within the SQL unless you
explicitly declare them as parameters.
What is easier though is to delimit the statement so that the form reference
is outside the quotes allowing VBA to return the value. Then you execute a
SQL statement that contains the value found at the form reference instead of
the form reference itself.
strSQl = "UPDATE tblReferrals " & _
"INNER JOIN tblVictimReferral " & _
"ON tblReferrals.ReferralID = tblVictimReferral.ReferralID " &
_
"SET tblVictimReferral.VicRef_Relation2 = " & [Forms]!
[frmVictimReferral]![VicRef_Relation2] & " " & _
"WHERE (((tblReferrals.ReferralID)=" &
[Forms]![frmVictimReferral]![ReferralID] & "));"
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com- Hide quoted text -
- Show quoted text -
.
- Follow-Ups:
- Re: dbs.Execute strSQL error - Too few parameters
- From: Rick Brandt
- Re: dbs.Execute strSQL error - Too few parameters
- References:
- dbs.Execute strSQL error - Too few parameters
- From: HeislerKurt
- Re: dbs.Execute strSQL error - Too few parameters
- From: Rick Brandt
- dbs.Execute strSQL error - Too few parameters
- Prev by Date: Re: Can I open forms randomly?
- Next by Date: Jetcomp & Access 2007
- Previous by thread: Re: dbs.Execute strSQL error - Too few parameters
- Next by thread: Re: dbs.Execute strSQL error - Too few parameters
- Index(es):
Relevant Pages
|