473,666 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to embed and format sql in VBA

subedimite
21 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. Dim dbs As Database
  2. Dim rs As DAO.Recordset
  3. Dim strSQL As String
  4. Set dbs = CurrentDb
  5.  
  6.  
  7. strSQL = "SELECT MyTests.Preconditions FROM QryTestFailure, MyTests WHERE ((([qryTestFailure]![TestID])=[MyTests]![RecNum]));"
  8.  
  9. Set rs = dbs.OpenRecordset(strSQL, dbOpenDynaset)
  10. NoOfRecords1 = rs.RecordCount
  11.  
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 ‘queryTestFailu re’ and table ‘MyTests’ (I should have called this ‘tblMytest s’:) ). 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
Jun 2 '10 #1
5 2647
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
Jun 2 '10 #2
subedimite
21 New Member
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?
Jun 2 '10 #3
subedimite
21 New Member
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.
Jun 2 '10 #4
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
Expand|Select|Wrap|Line Numbers
  1. Dim dbs As Database 
  2. Dim rs As DAO.Recordset 
  3. Dim strSQL As String 
  4. Set dbs = CurrentDb 
  5.  
  6.  
  7. strSQL = "SELECT MyTests.Preconditions FROM QryTestFailure, MyTests WHERE ((([qryTestFailure]![TestID])=[MyTests]![RecNum]));" 
  8.  
  9. Set rs = dbs.OpenRecordset(strSQL, dbOpenDynaset) 
  10. rs.MoveLast
  11. NoOfRecords1 = rs.RecordCount 
  12. msgbox NoOfRecords1 
  13.  
Jun 2 '10 #5
subedimite
21 New Member
@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.
Jun 3 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3109
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, which needs a Quicktime plugin, and one Java applet. He's also kindly supplied me with sample HTML code for each. The code looks like this (simplified):
10
6316
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 tag whose source is big SVG file, whose dimensions are unknown. If it is bigger than the screen, the rest of the SVG is clipped and not shown. I would like to force the embed tag to scroll in that case.
0
1394
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 P ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>wH7cq4Ky8EGU49PmVxwSaA==</Id>
8
3077
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, they use the <embed> tag and are therefore not compliant. I've found a couple of work arounds for Flash files, but none for ..WMV files. The client does not want to files to be transferred to a different format. Does anyone have the compliant code...
24
6254
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 can't figure out how to embed an image. Thanks for your time. -- Manuel
6
1481
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 I've been working to replace using ASP.NET master pages. Right now I'm trying to find a solution for some of our older and externally linked content. A good proportion of this content get loaded into the content frame, leaving the header and...
8
13658
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 for the setup, and compiles the whole thing into one EXE. How do i embed resources, and access them, into that assembly?
0
3938
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 string as: ------------------------------------------------------------------------------------------------ Dim fileNameXL As String = "_MYEXCEL_REPORTS.XLS" Dim pathNameXL As String = "\EXCEL_TEMP\"
2
8069
dream party
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 did not understand some parameters totally in the HTML tag. These days when I was surfing the Internet I have found some comprehensive introduction to these two tags. I read it and conclude it with my own words; I think it will be useful to us, so I...
0
8444
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8869
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7386
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1775
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.