Type mismatch DCount

  • Thread starter Thread starter govince
  • Start date Start date
G

govince

So, this has to be the simplest expression posted in a newsgroup.

I am counting the numbers of rows in a table (vomain)

my_count=DCount("ID","vomain")

Why I am I getting a Type Mismatch error?

I tried using "ID" (Numbers only)
and "voname" (Text) both return the same error.

Please help !!!
 
So, this has to be the simplest expression posted in a newsgroup.

I am counting the numbers of rows in a table (vomain)

my_count=DCount("ID","vomain")

Why I am I getting a Type Mismatch error?

I tried using "ID" (Numbers only)
and "voname" (Text) both return the same error.

Please help !!!

How is my_count defined?
 
Thanks Dirk,

My_count is defined in dim
I'm using my_count to display the result in a webpage.

Vince
 
Thanks Dirk,

My_count is defined in dim

You mean, as in

Dim my_count

? Meaning that my_count is a Variant. That should be okay. Hmm.
I'm using my_count to display the result in a webpage.

What do you mean by this? Is this code executing in an Access module,
or in VBScript on an ASP page, or what?
 
Yes, as in Dim my_count

This is being used in an ASP page. Displayed further down as
<%=my_count%>

I have been trying to figure that out for a while, but not luck.
Thanks for the help.

Vince
 
Yes, as in Dim my_count

This is being used in an ASP page. Displayed further down as
<%=my_count%>

I have been trying to figure that out for a while, but not luck.
Thanks for the help.

Vince

But DCount is not going to be meaningful on its own in an ASP page --
it's an Access function, and only defined within the Access application.
Does your ASP page contain an Access application object within which
your database has been opened as the current database? Note -- I
certainly wouldn't create one just for this purpose; normally I'd
expect you to open a recordset on a query to get the count, instead. Do
you have a DAO or ADO database object open?
 
Hi Dirk,

Yes, this is part of my code. I am also using the database to populate
drop boxes in the form, and that works fine.

Dim my_count, volanguage,ID, RS, sql, languageid, dcount,RS1,SQL1

<!--#include virtual="/data/connection_open.asp" -->
<%
SQL = "SELECT volanguage, ID FROM volanguage ORDER BY volanguage"
Set RS = conn.Execute(sql)
SQL1 = "SELECT ID FROM vomain"
Set RS1 = conn.Execute(sql1)

my_count=DCount("ID","vomain")%> ------------ (This is the problem
line)


Should I be using a different function to count the rows in ASP ?
Thanks for your continued help.

Vince
 
Hi Dirk,

This part of my code

I am also using the database to populate some drop down boxes.

<%@ LANGUAGE="VBScript" %>
<%Option Explicit%>
<!--#include virtual="/data/connection_open.asp" -->

Dim my_count, volanguage,ID, RS, sql, languageid, dcount,RS1,SQL1

SQL = "SELECT volanguage, ID FROM volanguage ORDER BY volanguage"
Set RS = conn.Execute(sql)

my_count=DCount("ID","vomain")

This is the code in connection_open.asp. (Removed the path)

Dim conn, strMyConnectionInfo
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=[path]ws.mdb"
Thanks for your continued help...

Vince
 
Hi Dirk,

Yes, this is part of my code. I am also using the database to populate
drop boxes in the form, and that works fine.

Dim my_count, volanguage,ID, RS, sql, languageid, dcount,RS1,SQL1

<!--#include virtual="/data/connection_open.asp" -->
<%
SQL = "SELECT volanguage, ID FROM volanguage ORDER BY volanguage"
Set RS = conn.Execute(sql)
SQL1 = "SELECT ID FROM vomain"
Set RS1 = conn.Execute(sql1)

my_count=DCount("ID","vomain")%> ------------ (This is the problem
line)


Should I be using a different function to count the rows in ASP ?

Yes. As I said, DCount is not available outside of the Access
application itself, and you are not working inside Access, even though
you may have an Access database file open. Actually, it should properly
be called a "Jet" database, not an "Access" database -- Access itself
*uses* the Jet database as its default data store, but the Access
application is actually independent of the database format itself.

Anyway, try something like this:

Dim RSCount

Set RSCount = conn.Execute("SELECT Count(ID) FROM vomain")
my_count = RSCount.Fields(0).Value
RSCount.Close
Set RSCount = Nothing

That may not be exactly right, but it should be close.
 
It absolutely works perfectly !

Thank you so much. Now I have to go the the store and buy some glue for
my hair :-)

Vince
 
Back
Top