473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Why is my vba sql not returning the correct value for a field?

I'm using Access 2007. I have a fairly simple function (code below) that is meant to get a count of 1 field based on criteria in 2 other fields. It works fine when I copy the sql into a query, but when I run the function it returns 0 as the value. I'm sure there is something simple I'm missing, but I can't figure out what. Any ideas?

Public Function CCDNASub(myMonth As Integer, myYear As Integer) As Integer
Dim mySQL As String
Dim cnn1 As ADODB.Connection
Dim myRS As New ADODB.Recordset
'Set up Recordset
Set cnn1 = CurrentProject.Connection
myRS.ActiveConnection = cnn1
myRS.CursorType = adOpenKeyset
myRS.LockType = adLockOptimistic
mySQL = "SELECT DISTINCTROW Count(qryCCDNASubmitList.Case) AS CountOfCase"
mySQL = mySQL + " FROM qryCCDNASubmitList WHERE (((qryCCDNASubmitList.SubMo)="
mySQL = mySQL + CStr(myMonth) + ") AND ((qryCCDNASubmitList.SubYr)=" + CStr(myYear) + "))"

myRS.Open mySQL
'It's returning a recordcount of 1 so the problem doesn't appear to be here
If myRS.RecordCount = 0 Then
CCDNASub = 0
Else: CCDNASub = myRS.Fields(0)
End If
myRS.Close
Set myRS = Nothing
Set cnn1 = Nothing

End Function
Aug 19 '10 #1
1 1446
Actually, never mind. I've been working on this for days and I just fixed it by changing the sql. I still don't know why the previous one didn't work, but I've got a working version now.
Aug 19 '10 #2

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

Similar topics

9
by: mjm | last post by:
Folks, Stroustrup indicates that returning by value can be faster than returning by reference but gives no details as to the size of the returned object up to which this holds. My question is...
3
by: Phoenix | last post by:
I am trying to print date headings over comments (as headings) I have a simple XML file : <comments> <comment id=1234 yyyymmdd="20041230" flag="Y">..text..</comment> <comment id=1309...
0
by: Epson Barnett | last post by:
I have a C# Web application I'm working on that loads a csv file on application start. The csv is an inventory file which is used to create a collection in the Application object. If the collection...
11
by: JKop | last post by:
AnyClass Blah() { AnyClass poo; return poo; } As we all know, in the above, the compiler is entitled to:
8
by: Roy Gourgi | last post by:
Hi, I would like to able to able to return a value from a called function but also retain the loop counter in the called function the next time I call it again. TIA Roy
4
by: Earl T | last post by:
When I try to get the netscape version for version 7, I get the HttpBrowserCapabilities class returning the version as 5 and not 7. (see code and output below) CODE HttpBrowserCapabilities...
2
by: Nathan Sokalski | last post by:
I have a DropDownList that is returning the value from index 0 regardless of which item is selected. The code that I am using to test which index it is returning is: Label1.Text =...
0
by: thisis | last post by:
Hi All, I'm getting an error on my ASP page: Microsoft VBScript runtime error '800a000d' Type mismatch: 'StoreFileIntoField' I assume - 99.5% - the error is generated because of worng...
0
by: thisis | last post by:
Hi All, I'm getting an error on my ASP page: Microsoft VBScript runtime error '800a000d' Type mismatch: 'StoreFileIntoField' I assume - 99.5% - the error is generated because of worng...
2
by: vsc33 | last post by:
Hello, I have a vb.net application that runs on a server. There are five client PC's that are connected to the server and all the data is saved on the server from my vb.net application. To add...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...

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.