Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Dcount Problem

Discussion in 'Information Technology' started by Mark, Nov 5, 2005.

Tags:
  1. Mark

    Mark
    Expand Collapse
    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
     
  2. Loading...

    Similar Threads Forum Date
    Sikh News Sikhs Face Problems While Carrying Kirpans In Khyber-Pakhtunkhwa - SikhSiyasat.Net Breaking News Jul 29, 2016
    "Dasam" Granth - A Look At The Core Problems Dasam Granth Oct 21, 2015
    Problems In Life Sikh Sikhi Sikhism Apr 13, 2015
    How can I make decent and useful friends and from where ?? most people have a problem with me Sikh Youth Oct 23, 2013
    The Problem with Taking Too Many Vitamins Health & Nutrition Oct 18, 2013

  3. Wayne Morgan

    Wayne Morgan
    Expand Collapse
    Guest

    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" <Mark@discussions.microsoft.com> wrote in message
    news:6475C3F0-9D80-4539-AACA-6DD4D25D693B@microsoft.com...
    > 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
     
  4. Mark

    Mark
    Expand Collapse
    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" wrote:

    > 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" <Mark@discussions.microsoft.com> wrote in message
    > news:6475C3F0-9D80-4539-AACA-6DD4D25D693B@microsoft.com...
    > > 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

    >
    >
    >
     

Share This Page