473,480 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DCount involving 2 fields

Hi, I had a DCount within a module on records in a table where CustSuffix =
0. I now need to DCount where CustSuffix = 0 and the type of cost Suffix
(Suffix in table) = G. I can't get both requirements to work and have tried
a number of different formats. At the moment I am getting an object
required error message.

This is the current code:

Function UpdateDistributionCost(Suff As String) ' adds new record if none
exists, prompting for cost, else updates existing distribution cost
Dim db As Database
Dim InvoiceAudit As Recordset
Dim DistCost As Currency
Dim Answer, Status, St As String
Dim OrigValue As Currency
Dim Resp As Long
Dim DC As Variant
Resp = MsgBox("Do you wish to edit/add a frozen G Distribution Cost?",
vbYesNo, "Edit Distribution Cost")
If Resp = vbYes Then

If DCount("CustSuffix", "tblCustomerDisributionCost", "[CustSuffix]
= '" & Suff And [Suffix] = "G") = 0 Then
' NEED TO SET UP CUSTOMER DISTRIBUTION COST
Status = "new"
OrigValue = 0
..........snipped

Thanks

Will
Nov 13 '05 #1
4 7527
Close, try

DCount("CustSuffix", "tblCustomerDisributionCost", "[CustSuffix] = " & Suff
& " And [Suffix] = ""G""") = 0

Since you indicate Suff is a number, you don't need quotes around it. You
could also use single quotes instead of the multiple double quotes around G.
The advantage of the multiple double quotes is it will work if the value
contains a single quote, such as when searching last names (i.e. O'Hare). If
Suff is really a text value then:

DCount("CustSuffix", "tblCustomerDisributionCost", "[CustSuffix] = """ &
Suff & """ And [Suffix] = ""G""") = 0

--
Wayne Morgan
Microsoft Access MVP
"Will" <wi*****************@f2s.com> wrote in message
news:ch**********@news.freedom2surf.net...
Hi, I had a DCount within a module on records in a table where CustSuffix
=
0. I now need to DCount where CustSuffix = 0 and the type of cost Suffix
(Suffix in table) = G. I can't get both requirements to work and have
tried
a number of different formats. At the moment I am getting an object
required error message.

This is the current code:

Function UpdateDistributionCost(Suff As String) ' adds new record if none
exists, prompting for cost, else updates existing distribution cost
Dim db As Database
Dim InvoiceAudit As Recordset
Dim DistCost As Currency
Dim Answer, Status, St As String
Dim OrigValue As Currency
Dim Resp As Long
Dim DC As Variant
Resp = MsgBox("Do you wish to edit/add a frozen G Distribution Cost?",
vbYesNo, "Edit Distribution Cost")
If Resp = vbYes Then

If DCount("CustSuffix", "tblCustomerDisributionCost", "[CustSuffix]
= '" & Suff And [Suffix] = "G") = 0 Then
' NEED TO SET UP CUSTOMER DISTRIBUTION COST
Status = "new"
OrigValue = 0
..........snipped

Thanks

Will

Nov 13 '05 #2
If DCount("CustSuffix", "tblCustomerDisributionCost", "[CustSuffix] = '" &
Suff & "' And [Suffix] = 'G'") = 0 Then

exagerrated for clarity, the 3rd argument is

"[CustSuffix] = ' " & Suff & " ' And [Suffix] = ' G ' "

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Will" <wi*****************@f2s.com> wrote in message
news:ch**********@news.freedom2surf.net...
Hi, I had a DCount within a module on records in a table where CustSuffix = 0. I now need to DCount where CustSuffix = 0 and the type of cost Suffix
(Suffix in table) = G. I can't get both requirements to work and have tried a number of different formats. At the moment I am getting an object
required error message.

This is the current code:

Function UpdateDistributionCost(Suff As String) ' adds new record if none
exists, prompting for cost, else updates existing distribution cost
Dim db As Database
Dim InvoiceAudit As Recordset
Dim DistCost As Currency
Dim Answer, Status, St As String
Dim OrigValue As Currency
Dim Resp As Long
Dim DC As Variant
Resp = MsgBox("Do you wish to edit/add a frozen G Distribution Cost?",
vbYesNo, "Edit Distribution Cost")
If Resp = vbYes Then

If DCount("CustSuffix", "tblCustomerDisributionCost", "[CustSuffix] = '" & Suff And [Suffix] = "G") = 0 Then
' NEED TO SET UP CUSTOMER DISTRIBUTION COST
Status = "new"
OrigValue = 0
..........snipped

Thanks

Will

Nov 13 '05 #3
Thank you both your help, Suff is in fact really a text file.
Later on in the same part of code I need to need to Select on the same basis
as the DCount. Where Suffix = G

My current working code looks like this:
St = "SELECT * FROM tblCustomerDisributionCost WHERE [CustSuffix] ='" & Suff
& "';"
Set rs = db.OpenRecordset(St)
rs.Edit

I have tried copying the code from DCount and altering it but I keep getting
Compile error: Variable not Defined. Someone else has written this code and
I am editing it and don't really understand what the "';" does at the end of
the line? Any help would be grateful.

Thanks
"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:2q******************@newssvr33.news.prodigy.c om...
Close, try

DCount("CustSuffix", "tblCustomerDisributionCost", "[CustSuffix] = " & Suff & " And [Suffix] = ""G""") = 0

Since you indicate Suff is a number, you don't need quotes around it. You
could also use single quotes instead of the multiple double quotes around G. The advantage of the multiple double quotes is it will work if the value
contains a single quote, such as when searching last names (i.e. O'Hare). If Suff is really a text value then:

DCount("CustSuffix", "tblCustomerDisributionCost", "[CustSuffix] = """ &
Suff & """ And [Suffix] = ""G""") = 0

--
Wayne Morgan
Microsoft Access MVP
"Will" <wi*****************@f2s.com> wrote in message
news:ch**********@news.freedom2surf.net...
Hi, I had a DCount within a module on records in a table where CustSuffix =
0. I now need to DCount where CustSuffix = 0 and the type of cost Suffix (Suffix in table) = G. I can't get both requirements to work and have
tried
a number of different formats. At the moment I am getting an object
required error message.

This is the current code:

Function UpdateDistributionCost(Suff As String) ' adds new record if none exists, prompting for cost, else updates existing distribution cost
Dim db As Database
Dim InvoiceAudit As Recordset
Dim DistCost As Currency
Dim Answer, Status, St As String
Dim OrigValue As Currency
Dim Resp As Long
Dim DC As Variant
Resp = MsgBox("Do you wish to edit/add a frozen G Distribution Cost?", vbYesNo, "Edit Distribution Cost")
If Resp = vbYes Then

If DCount("CustSuffix", "tblCustomerDisributionCost", "[CustSuffix] = '" & Suff And [Suffix] = "G") = 0 Then
' NEED TO SET UP CUSTOMER DISTRIBUTION COST
Status = "new"
OrigValue = 0
..........snipped

Thanks

Will


Nov 13 '05 #4
The ";" at the end of the line is just the standard way a SQL statement is
written. Open one of your queries in the query tab of the database window
and go to SQL view. You will notice they end with a ;.

In the code example you gave, the variables are St, Suff, and rs. Is there a
Dim statement in the procedure that has these listed? They may be in
separate Dim statements. If you are modifying the DCount code, show us what
you are coming up with after you make the modifications. You may have some
quotes in the wrong place, making Access think something is a variable when
you don't intend it to be.

--
Wayne Morgan
Microsoft Access MVP
"Will" <wi*****************@f2s.com> wrote in message
news:ch**********@news.freedom2surf.net...
Thank you both your help, Suff is in fact really a text file.
Later on in the same part of code I need to need to Select on the same
basis
as the DCount. Where Suffix = G

My current working code looks like this:
St = "SELECT * FROM tblCustomerDisributionCost WHERE [CustSuffix] ='" &
Suff
& "';"
Set rs = db.OpenRecordset(St)
rs.Edit

I have tried copying the code from DCount and altering it but I keep
getting
Compile error: Variable not Defined. Someone else has written this code
and
I am editing it and don't really understand what the "';" does at the end
of
the line? Any help would be grateful.

Thanks
"Wayne Morgan" <co***************************@hotmail.com> wrote in
message
news:2q******************@newssvr33.news.prodigy.c om...
Close, try

DCount("CustSuffix", "tblCustomerDisributionCost", "[CustSuffix] = " &

Suff
& " And [Suffix] = ""G""") = 0

Since you indicate Suff is a number, you don't need quotes around it. You
could also use single quotes instead of the multiple double quotes around

G.
The advantage of the multiple double quotes is it will work if the value
contains a single quote, such as when searching last names (i.e. O'Hare).

If
Suff is really a text value then:

DCount("CustSuffix", "tblCustomerDisributionCost", "[CustSuffix] = """ &
Suff & """ And [Suffix] = ""G""") = 0

--
Wayne Morgan
Microsoft Access MVP
"Will" <wi*****************@f2s.com> wrote in message
news:ch**********@news.freedom2surf.net...
> Hi, I had a DCount within a module on records in a table where CustSuffix > =
> 0. I now need to DCount where CustSuffix = 0 and the type of cost Suffix > (Suffix in table) = G. I can't get both requirements to work and have
> tried
> a number of different formats. At the moment I am getting an object
> required error message.
>
> This is the current code:
>
> Function UpdateDistributionCost(Suff As String) ' adds new record if none > exists, prompting for cost, else updates existing distribution cost
> Dim db As Database
> Dim InvoiceAudit As Recordset
> Dim DistCost As Currency
> Dim Answer, Status, St As String
> Dim OrigValue As Currency
> Dim Resp As Long
> Dim DC As Variant
>
>
> Resp = MsgBox("Do you wish to edit/add a frozen G Distribution Cost?", > vbYesNo, "Edit Distribution Cost")
> If Resp = vbYes Then
>
> If DCount("CustSuffix", "tblCustomerDisributionCost", "[CustSuffix] > = '" & Suff And [Suffix] = "G") = 0 Then
> ' NEED TO SET UP CUSTOMER DISTRIBUTION COST
> Status = "new"
> OrigValue = 0
> ..........snipped
>
> Thanks
>
> Will
>
>



Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1535
by: Simon Matthews | last post by:
Hope someone can help an Access beginner! I've just started keeping my surgical logbook on access and it's a simple flat-file affair. I have created several queries that will list cases...
6
3298
by: Mike Conklin | last post by:
This one really has me going. Probably something silly. I'm using dcount for a report to determine the number of different types of tests proctored in a semester. My report is based on a...
15
2943
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting...
1
1830
by: SheldonMopes | last post by:
I'm having difficulty with the DCount function, not getting the results that I want. Field1A and Field2A are fields in TableA matching Field1B and Field2B in TableB Using a calculated...
2
511
by: solar | last post by:
DCount in a query How can i sum up all the fields in the query? My query consists of the table products.The first field is Productid, the second is ProductName. The next fields are the quantities...
9
2628
by: F6GGR | last post by:
Hello, I use Access 2000 and i want to use the Dcount function in a form. I try to build this expression in a texte zone : I tried many ways usuing and mixing " and/or ' but Access always says...
7
31983
by: Michael R | last post by:
Good afternoon. I'm stucked in composing the syntax for DCount expression in a select query. The query qryCustomers has CustomerID field, the DCount function uses tblLoans with LoanDate and Id fields...
4
1431
by: ashitaka65 | last post by:
hey, i'm writting a database and in my report am tryin to have dcounts count some diffrent fields i would like to know if there is a way to have your dcount skip or not count a field or if there is...
3
4853
by: ringer | last post by:
I am trying to add a functionality into a db I use for my checkbook that will help me plan for and save money for future large expenses. Into a table called tblFutureTransactions I want to enter...
0
7049
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,...
0
6912
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
7092
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...
1
6744
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...
0
6981
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5348
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,...
0
3000
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
188
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...

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.