This is the first time I am trying to call SQL in VBA. I am trying to read the result of the SQL in a recordset.
My Code Looks like this: -
Dim dbs As Database
-
Dim rs As DAO.Recordset
-
Dim strSQL As String
-
Set dbs = CurrentDb
-
-
-
strSQL = "SELECT MyTests.Preconditions FROM QryTestFailure, MyTests WHERE ((([qryTestFailure]![TestID])=[MyTests]![RecNum]));"
-
-
Set rs = dbs.OpenRecordset(strSQL, dbOpenDynaset)
-
NoOfRecords1 = rs.RecordCount
-
I have directly copied SQL from the Query design, with the double quotes added at the start and the end. The code compiles but does not work. The SQL itself is working while called from Access query object. The query selects data from another query ‘queryTestFailure’ and table ‘MyTests’ (I should have called this ‘tblMytests’:) ). Reading some articles in the web it seems like I need to modify the SQL string inserting the symbols: doublequotes, ampersand and single quotes. Why do I need to do that, Could I please have some help on it how is done?
Thanks
5 2638 Delerna 1,134
Recognized Expert Top Contributor
Your code looks OK to me
Why do you say it doesn't work ?
I have a feeling I know why but I will wait for you to answer
Well, I am saying it does not work because when I run the query seperately, I end up with 12 records. In the above code rs.RecordCount is returning 1. Also when I use GetRows method to read the recordset ,I am ending up with nothing. Am I doing something silly:) or missing something obvious?
Hi, When I restarted the database it was working.
Just was not confident as it was pretty much the first time, I did this.
However when I reset the code that’s where it seems to be the problem. The 'rs.RecordCount ' now returns 6 which is a right number; However NoOfRecords does not get assigned that value. It is showing the value of 1 (Very wierd). It seems, this all is due to lack of ' error handling'
I need to have a look at it bit deeper.
Delerna 1,134
Recognized Expert Top Contributor
Thought that would be the answer
The thing to be aware of here is, immediately after a recordset has been opened rs.recordcount will not return the number of records
it only returns 1.
I am not sure why but a little research would reveal that
Try this -
Dim dbs As Database
-
Dim rs As DAO.Recordset
-
Dim strSQL As String
-
Set dbs = CurrentDb
-
-
-
strSQL = "SELECT MyTests.Preconditions FROM QryTestFailure, MyTests WHERE ((([qryTestFailure]![TestID])=[MyTests]![RecNum]));"
-
-
Set rs = dbs.OpenRecordset(strSQL, dbOpenDynaset)
-
rs.MoveLast
-
NoOfRecords1 = rs.RecordCount
-
msgbox NoOfRecords1
-
@Delerna
Hi Thanks for that:
I got the answer; RecordCount Method can only count all the records when it fully moves to the last Record. I hope I am right.
But this happened only when I read the recordset form SQL. When I read it directly from the table or Query it has no problem.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Wolfgang Schwanke |
last post by:
Dear usenet,
I'm having the following small problem.
I've been ask to add some Quicktime panoramas to a website. The author of
the panoramas has made two versions of each: One in MOV format,...
|
by: Anna |
last post by:
Hi all.
I don't have a very deep understanding of CSS and this question might
sound stupid for you. Sorry for that.
Can the overflow CSS property be applied to the embed tag?
I have an embed...
|
by: Jin P via .NET 247 |
last post by:
how you guys embed an audio file (let say wav format) in a resx file? I can embed images but somehow
when I try to embed audios, it said out of memory.
--------------------------------
From: Jin...
|
by: Cowan Services |
last post by:
My apologies if this has been covered before, but I was unable to download
messages before 11/23/05.
I am trying to bring some HTML pages w/embedded .WMV files into W3C
compliance. Right now,...
|
by: Manuel |
last post by:
Is it possible to embed an image, like a company logo in a CDOSYS generated
message?
If yes, I´ll apreciate some code sample. I´ve been able to format messages
in html the way I like, but I...
| |
by: emorgoch |
last post by:
Hi there.
I'm currently working on a project involving rebuilding our local
intranet site. The site was originally developed using frames, defining
a header, sidebar, and content area, which...
|
by: CodeLeon |
last post by:
Hi, All. I am creating a setup program. The way it works is that the
user creates their setup info, my program generates the C# code for a
setup executable, embeds the xml file containing the info...
|
by: =?Utf-8?B?Tml5YXpp?= |
last post by:
Hi all,
Does anyone know how to embed the Excel file in VB.NET 2005 Resources?
Here is what I am doing at the moment:
1) In my VB.NET 2005 project code I load the excel with it path into...
|
by: dream party |
last post by:
Inserting a Flash (SWF, FLV) file into HTML web page is already an old and familiar thing to all of us. It is a rather non-flexible thing that just to edit some options in the template. However, I...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |