473,406 Members | 2,336 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,406 software developers and data experts.

Continuous Form DCount #Error On New Record

124 100+
On a continuous form I have a DCount expression as the control source for one of my textbox controls. The expression is thus:

=DCount("DegReqDiscId","DegReqDisc","DegReqId = " & [txtDegReqId])

It works fine except that on the new record row it displays #Error. I know it's doing that because the txtDegReqId is (New) and will be so until a new record is entered. Is there a way that I can get it to show blank (or 0) for the new record row?
Apr 20 '10 #1

✓ answered by TheSmileyCoder

Hi, and welcome to Bytes

Yes there is, we just make sure to handle the Null case. Nz([Field],value) will return value if [Field] is null.

We could use that like:
Expand|Select|Wrap|Line Numbers
  1. =DCount("DegReqDiscId","DegReqDisc","DegReqId = " & nz([txtDegReqId],0))
so now, if txtDegReqID is null the function will return 0 (And assuming that there is no ID with the value 0, the dcount will now return 0 as well)

However we can make it a bit smarter. There is no need to take up query time to perform a query, if know the answer allready. Lets use an IIf statement.
Expand|Select|Wrap|Line Numbers
  1. =IIf(isNull([txtDegReqId]),0,DCount("DegReqDiscId","DegReqDisc","DegReqId = " & [txtDegReqId]))
Now the query will only be performed if there is an actual ID.

2 4861
TheSmileyCoder
2,322 Expert Mod 2GB
Hi, and welcome to Bytes

Yes there is, we just make sure to handle the Null case. Nz([Field],value) will return value if [Field] is null.

We could use that like:
Expand|Select|Wrap|Line Numbers
  1. =DCount("DegReqDiscId","DegReqDisc","DegReqId = " & nz([txtDegReqId],0))
so now, if txtDegReqID is null the function will return 0 (And assuming that there is no ID with the value 0, the dcount will now return 0 as well)

However we can make it a bit smarter. There is no need to take up query time to perform a query, if know the answer allready. Lets use an IIf statement.
Expand|Select|Wrap|Line Numbers
  1. =IIf(isNull([txtDegReqId]),0,DCount("DegReqDiscId","DegReqDisc","DegReqId = " & [txtDegReqId]))
Now the query will only be performed if there is an actual ID.
Apr 21 '10 #2
bullfrog83
124 100+
That's what I was doing wrong! I was putting the nz function around my entire =DCount expression instead of just the [txtDegReqId]. However, I like your use of the IIf function. I'd figured that the shorter your code is, the faster the performance, but apparently that's not always the case?

Thank you very much! Works like a charm!
Apr 21 '10 #3

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

Similar topics

3
by: Mark | last post by:
Hi there, I have a subform, set as a continuous form. When a user selects a particular record in that subform, how can I make that particular record stand out (color or font change, size, etc) from...
4
by: Kathy | last post by:
What is the standard technique for handling the fields in the following scenario on a continuous form? Multiple Divisions. Each Division has multiple Buildings. Each Building has a Supervisor. ...
3
by: Leo | last post by:
Hi everybody, Is there a way to fill a continuous form with an ADO recordset? Normally when I populate the form with the recordset only the first record is shown. I want to fill all records....
20
by: Robert | last post by:
Need some help to stop me going around in circles on this one.... Have a nested subform (subform2) which simulates a continuous form for the record on the parent subform. Subform2 has rows of...
3
by: ApexData | last post by:
I am using a continuous form for display purposes. Above this form, a single record is displayed so that when the user presses my NewButton they can enter a NewRecord which gets added to the...
3
by: eighthman11 | last post by:
Using Access 2000. I have a continuous form which for simplicity sack has two fields Social Security Number and Last Name. In the header of the continuous form I have a textbox where you can...
5
by: eighthman11 | last post by:
Hi everyone: This is probably a pretty simple problem but it is driving me nuts. Using Access 2000. I have a continuous form which list several thousand inventory items. The user can enter a...
10
by: sara | last post by:
Hi - I have been struggling with solution ideas for this now for almost 2 weeks, and have not been able to figure this out. I have a user who creates a Purchase Order (tblPOData). In some...
13
by: eighthman11 | last post by:
using Access 2003 and sql server version 8.0 Hey everyone. Created a text box where the user types in an Inventory number and it takes them to that inventory number on the contimuous form. The...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.