RE: This Inner join works in MS Access, but not in VB6?

Tech-Archive recommends: Fix windows errors by optimizing your registry



My thanks to you both, Ralph and Douglas,

About same provider: VB is using Jet 4.0. I suppose that is the same as
Access 2002.

You identified the solution which was to delimit the embedded long integer
variable lngPerID with single quotes, i.e. Perloc.xPerID= '" & lngPerID & '"
....

I am embarrassed to see an error I should have caught. On debugging, I did
a debug.print of the SQL select string and when I clicked on the lngPerID in
the VB6 immediate window, it displayed the current integer value of this
variable.

I misled myself from this to think that the SQL string was OK, and my mind
was closed to the possibility of error.

Now I realize that the appearance of the variable name in the immediate
window stands alone by virtue of the blanks delimiting it. So the VB IDE
will interpret the variable name into a value by clicking. But when SQL sees
it, it is treated as just some characters in the SQL string and not as a
symbol that must be interpreted.

The single quote delimiters cause the SQL parser to recognize the characters
composing the name as a variable to delimited.

Again, thanks for kind assistance.

--
Lamont Phemister


"Lamont" wrote:

Thank you for helping me to solve this mystery.

I have a select statement that works fine in MS Access, but fails in VB6,
with an error message that says "No value given for one or more required
parameters."

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.

I have two tables, Loc (location) and Per (person) and the rows are in many
to many correspondence
to each other.

These tables are linke by an intersection table 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.

Loc PerLoc Per
====== ===== ===

LocID------------| PerLocID |-------------PerID
Adr |--------------xLocID | LastName
City xPerID--------------| FirstName
State
Salutation
Zip
EnvelopeName


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. Here is the query that works in Access:

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.

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
.



Relevant Pages

  • Re: SQL Express - Identity specification property - how to change
    ... FOO_ID int identity, ... Tony Rogerson, SQL Server MVP ... They are making unfortunately frequent use of the IDENTITY column in conjunction with Primary Key. ... IDENTITY has none of the properties of a data type because it is not a data type at all. ...
    (comp.databases.ms-sqlserver)
  • Re: Binding and adding rows with SQL identity column
    ... Each time you call AddNew then the DataTable generates a new ... Each time an update is done then the real primary key ... > generated by the built-in wizard in VS2003. ... > identity column on the sql table, perhaps this would all the fine and I ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: What happens after 2^32 autonum keys are exhausted?
    ... Tony Rogerson, SQL Server MVP ... generated primary key despite the risk of a hardware or software error or a fault in the space-time continuum. ... identifier and have to invent one, follow the data design (data ...
    (comp.databases)
  • Re: sliced find in Linq
    ... by over all of the returned columns. ... Since the original query was unordered, I'd like the above SQL to ... (Perhaps your table doesn't have a primary key though?) ... didn't specify the ordering, so any ordering could have been used. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can a query find info X numbr of rows from target info?
    ... "Ann Scharpf" wrote: ... > each row is sequentially numbered, giving me the desired explicit sort order. ... > an exact comparison between my SQL & your advice. ... Do you have Row names (Primary Key). ...
    (microsoft.public.access.queries)