Dcount Problem

G

Guest

Hi,
I have a form that is based on a query, i use this form to group customers
together based on warranty claims they have made. One customer can have
several claims and some customers will have un resolved claims. It is
important for me to count these records based on two fields, customer name
and a certain status of their claim. This is what my code looks like so far
and it mainly works...

Let cn = [CustomerName]

intx = DCount("[StatusID]", "qryfrm", "[Customername] = '" & cn & "' AND
[statusid] = 2")
inty = DCount("[StatusID]", "qryfrm", "[CustomerName] = '" & cn & "' ")
[count1] = inty

My probem happens when a customes name has a ' in it such as Captain's
Marine. The ' seems to be seen as part of the code and i get a error message
when i try to count the records. On a normal name such as Mark it works
perfectly. Is there anywas i can treat the whole customer name as a string?
Does anyone have some advice?

Thanks,
Mark
 
W

Wayne Morgan

You can use double quotes as the delimiter in your statements so that the
apostrophes in the names won't cause you a problem. To place a double quote
in a string without VBA thinking its the end of the string, you have to
double them. Using your first example, that would change it to:

intx = DCount("[StatusID]", "qryfrm", "[Customername] = """ & cn & """ AND
[statusid] = 2")

To give you an idea of what is happening, this

"this is a ""test"" string"

Would return

this is a "test" string
 
G

Guest

Hi Wayne,

Thank you very much, that helped me out a lot! This discussion page is a
wealth of information to new access programmers.

Mark

Wayne Morgan said:
You can use double quotes as the delimiter in your statements so that the
apostrophes in the names won't cause you a problem. To place a double quote
in a string without VBA thinking its the end of the string, you have to
double them. Using your first example, that would change it to:

intx = DCount("[StatusID]", "qryfrm", "[Customername] = """ & cn & """ AND
[statusid] = 2")

To give you an idea of what is happening, this

"this is a ""test"" string"

Would return

this is a "test" string

--
Wayne Morgan
MS Access MVP


Mark said:
Hi,
I have a form that is based on a query, i use this form to group customers
together based on warranty claims they have made. One customer can have
several claims and some customers will have un resolved claims. It is
important for me to count these records based on two fields, customer name
and a certain status of their claim. This is what my code looks like so
far
and it mainly works...

Let cn = [CustomerName]

intx = DCount("[StatusID]", "qryfrm", "[Customername] = '" & cn & "' AND
[statusid] = 2")
inty = DCount("[StatusID]", "qryfrm", "[CustomerName] = '" & cn & "' ")
[count1] = inty

My probem happens when a customes name has a ' in it such as Captain's
Marine. The ' seems to be seen as part of the code and i get a error
message
when i try to count the records. On a normal name such as Mark it works
perfectly. Is there anywas i can treat the whole customer name as a
string?
Does anyone have some advice?

Thanks,
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Dcount question 6
Access MS Access DCount function problem 0
dcount 1
DCount with AND 1
DCount on Left Join 2
Problem with FindFirst Method 4
Relationships and Form Query Problem 5
Dlookup or Dcount 4

Top