Re: Embedded SQL within VBA?
- From: "Peter Jamieson" <pjj@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 1 Sep 2007 09:23:33 +0100
Without going too deeply into areas that I'm not actualy that familiar with anyway, try using
objRecordSet.MoveLast
before testing the recordcount.
If you can't MoveLast, then the provider you are using probably defaults to using an "adOpenForwardOnly" cursortype (you can use the CursorType parameter of the Open method to try to specify the CursorType, but the provider may change the type if it doesn't support the one you asked for. For example, the Access/Jet OLE DB provider doesn't (or didn't) support dynamic cursors and will give you a Keyset cursor. You can check the cursor type post-Open by looking at
objRecordSet.CursorType
If you have an adOpenForwardONly cursor type, try changing it to any of the others - if you need to be able to update the recordset, use adOpenDynamic or adOpenKeyset, otherwise you may be able to use adOpenStatic. Then, if necessary, try using .MoveLast.
--
Peter Jamieson
http://tips.pjmsn.me.uk
"Rick Charnes" <rickxyz--nospam.zyxbadcharnes@xxxxxxxxxxxxxxx> wrote in message news:MPG.2142271770b03b009899ab@xxxxxxxxxxxxxxxxxxxxxxx
I have my ADO connection working fine now. But can anyone help me
figure out why .RecordCount is returning -1 here? MyValue is assigned
correctly. Thanks.
Dim rstcount As Integer
Dim myvalue as string
objRecordset.Source = "SELECT * FROM mytable WHERE name = 'UE'"
objRecordset.Open
myvalue = objRecordset.Fields("gen_value")
rstcount = objRecordset.RecordCount 'returns -1
In article <OP1QwAm6HHA.5136@xxxxxxxxxxxxxxxxxxxx>,
pjj@xxxxxxxxxxxxxxxxxxxxxxxxxx says...
> Am I asking VBA via ADO too much here?
No, but there may be a terminology gap if you are used to using SQL CURSORS
etc.
In ADO you would typically
a. open a Connection
b. open a RecordSet by specifying a COnnection, a piece of SQL, and a
couple of other parameters
.
- Follow-Ups:
- Re: Embedded SQL within VBA?
- From: Rick Charnes
- Re: Embedded SQL within VBA?
- Prev by Date: Re: Replacing Text w/Autotext - Greg, Ed, Graham,Russ
- Next by Date: Re: Replacing Text w/Autotext - Greg, Ed, Graham,Russ
- Previous by thread: Re: Reselect the drop down box on exit macro when not tabbed out o
- Next by thread: Re: Embedded SQL within VBA?
- Index(es):
Relevant Pages
|