Thank you for considering this problem.

I posted this question in the Active Data Objects forum before I detected
that this "General Discussion" forum seems to relate more to queries. Mea
Culpa.

I have two tables, Loc (location) and Per (person) and the rows are in many
to many correspondence to each other. Given a the primary key of a Per
record (PerID) in a variable named lngPerID which is obtained by clicking on
a row in a Per grid, my query needs to select all the locations with
which this person is association.

Table Per and table LOC are linked by an intersection table, PERLOC where
each record has a pointer to the primary key of the Loc table, and a pointer
to the primary key of the Per table. * indicates primary key

Table Table Table
Loc PerLoc Per
====== ===== ===
*LocID--------| *PerLocID ----------*PerID <---saved in
lngPerID
Adr |--------------xLocID | LastName
City xPerID----------| FirstName
State Salutation
Zip
EnvelopeName

The query following works fine in MS Access, but fails in VB6 with an error
message that says "No value given for one or
more required parameters." Err -2147217904

SELECT Loc.LocID, Loc.Adr, Loc.City, Loc.State, Loc.Zip
FROM Loc INNER JOIN PerLoc ON Loc.LocID = PerLoc.xLocID
WHERE (((PerLoc.xPerID)=[lngPerID]));
^
|____This value is given.

I have checked that the select statement names matches the table names until
I
am blue in the face. Is it possible that the "No value given for one or
more required parameters."
the only variable defined in the table is the temporary variable named
lngPerID, and it is clearly
seen in the code to hold the numeric value for the key of a record observed
in the table.

This query fails in VB6. (Code below)

Private sub DoRSLocSet()
Dim sSQL as string
sSQL = "SELECT Loc.LocID, Loc.Adr, Loc.City, Loc.State,
Loc.LocType, Loc.Zip, Loc.Country" & _
" FROM Loc INNER JOIN PerLoc ON Loc.LocID = PerLoc.xLocID" & _
" WHERE ((PerLoc.xPerID)=lngPerID);"
On Error Resume Next
rsLoc.Close
Err.Clear
On Error GoTo DoRsLocSetErr
With rsLoc
.ActiveConnection = cnnPer
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Properties("IRowsetIdentity") = True 'remove comment to display data
.Open sSQL, , , , adCmdText
End With
Exit Sub
DoRsLocSetErr:
MsgBox "ABORT DoRSLocSetErr = " & Err.Number & " " & Err.Description
Err.Clear
'End
End Sub


--
Lamont Phemister

Re: Query works in MS Access, but not in VB6 with ADO by Robert

Robert
Wed Oct 08 20:42:11 CDT 2008

Lamont wrote:
> Thank you for considering this problem.
>
> I posted this question in the Active Data Objects forum before I detected
> that this "General Discussion" forum seems to relate more to queries. Mea
> Culpa.
>
> I have two tables, Loc (location) and Per (person) and the rows are in many
> to many correspondence to each other. Given a the primary key of a Per
> record (PerID) in a variable named lngPerID which is obtained by clicking on
> a row in a Per grid, my query needs to select all the locations with
> which this person is association.
>
> Table Per and table LOC are linked by an intersection table, PERLOC where
> each record has a pointer to the primary key of the Loc table, and a pointer
> to the primary key of the Per table. * indicates primary key
>
> Table Table Table
> Loc PerLoc Per
> ====== ===== ===
> *LocID--------| *PerLocID ----------*PerID <---saved in lngPerID
> Adr |--------------xLocID | LastName
> City xPerID----------| FirstName
> State Salutation
> Zip
> EnvelopeName
>
> The query following works fine in MS Access, but fails in VB6 with an error
> message that says "No value given for one or
> more required parameters." Err -2147217904
>
> SELECT Loc.LocID, Loc.Adr, Loc.City, Loc.State, Loc.Zip
> FROM Loc INNER JOIN PerLoc ON Loc.LocID = PerLoc.xLocID
> WHERE (((PerLoc.xPerID)=[lngPerID]));
> ^
> |____This value is given.
>
> I have checked that the select statement names matches the table names until
> I
> am blue in the face. Is it possible that the "No value given for one or
> more required parameters."
> the only variable defined in the table is the temporary variable named
> lngPerID, and it is clearly
> seen in the code to hold the numeric value for the key of a record observed
> in the table.
>
> This query fails in VB6. (Code below)
>
> Private sub DoRSLocSet()
> Dim sSQL as string
> sSQL = "SELECT Loc.LocID, Loc.Adr, Loc.City, Loc.State,
> Loc.LocType, Loc.Zip, Loc.Country" & _
> " FROM Loc INNER JOIN PerLoc ON Loc.LocID = PerLoc.xLocID" & _
> " WHERE ((PerLoc.xPerID)=lngPerID);"
> On Error Resume Next
> rsLoc.Close
> Err.Clear
> On Error GoTo DoRsLocSetErr
> With rsLoc
> .ActiveConnection = cnnPer
> .CursorLocation = adUseServer
> .CursorType = adOpenKeyset
> .LockType = adLockOptimistic
> .Properties("IRowsetIdentity") = True 'remove comment to display data
> .Open sSQL, , , , adCmdText
> End With
> Exit Sub
> DoRsLocSetErr:
> MsgBox "ABORT DoRSLocSetErr = " & Err.Number & " " & Err.Description
> Err.Clear
> 'End
> End Sub

I'm a little confused as to what, exactly, lngPerID is. Is it a parameter
in the query or not? If it is, then you need to either specify what the
value for it is by using the .Parameters collection OR, more simply, modify
the text of your query before calling .Open.

For example:

sSQL = "SELECT Loc.LocID, Loc.Adr, Loc.City, Loc.State,
Loc.LocType, Loc.Zip, Loc.Country" & _
" FROM Loc INNER JOIN PerLoc ON Loc.LocID = PerLoc.xLocID" & _
" WHERE PerLoc.xPerID=" & lngPerID

(I've removed the WHERE clause parentheses and the closing semicolon - none
of them are necessary, they're just added cuz Access likes to add cluttering
punctuation. <g>)

But if you're doing it this way, then were is lngPerID being set?


Rob