473,386 Members | 1,674 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,386 software developers and data experts.

How to reference a control on a form in a DCount on the same form?

I need to count the number of occurrences of a particular employee based on the type of occurrence selected in a control drop down box. I am using a DCount on the same form to try to accomplish this.

Can anyone help me with the syntax of this DCount:

Expand|Select|Wrap|Line Numbers
  1. countOfOccurrence: DCount("Resolution","tblIssues","[tblIssues.Resolution] = Forms![subFormOccurrence].[drpResolution]")

Or does anyone have a better idea about how to do this?
Apr 9 '11 #1

✓ answered by Stewart Ross

Hi Amy. Three things. First, there is a mistake in the way you are referring to the resolution field in your DCount:

[tblIssues.Resolution] should be
[tblIssues].[Resolution], but you don't need to qualify it at all, so just [Resolution] will be fine.

Second, is the type of resolution selected from your combo control a text value or a number? As you have it at present you are treating this value as a number. If it is text, you need to enclose the value in single quotes.

Third, the control reference is being provided to DCount as part of the WHERE string, and this will defer its interpretation until the DCount is run. This can fail, depending on where and when the DCount is run. It is normal to pass the current value of the control into the WHERE clause instead, as you will see in the final example below (treating the comparison as text).

Expand|Select|Wrap|Line Numbers
  1. countOfOccurrence: DCount("Resolution","tblIssues","[Resolution] = '" & Forms![subFormOccurrence].[drpResolution] & "'")
If the resolution really is a number, then you won't need the single quotes at all:

Expand|Select|Wrap|Line Numbers
  1. countOfOccurrence: DCount("Resolution","tblIssues","[Resolution] = " & Forms![subFormOccurrence].[drpResolution])
If you are referring to a control on a subform, the normal way to refer to the control is like this:

Forms![Your Main Form Name]![Subform Name].Form![Subform control name]

I note that this is not what you have posted above, and I did not include the full syntax in my examples to keep them brief. Keep this in mind when trying to resolve the issues mentioned above - you will need to use the correct syntax for retrieving the value of drpResolution or the Where clause will simply not work at all.

I don't know the name of your main form, so all I can give is an exampple of what might be needed, and you would need to substitute the actual name of your main form accordingly:

Expand|Select|Wrap|Line Numbers
  1. countOfOccurrence: DCount("Resolution","tblIssues","[Resolution] = '" & Forms![Your MainForm Name]![subFormOccurrence].Form![drpResolution] & "'")


-Stewart

2 5190
Stewart Ross
2,545 Expert Mod 2GB
Hi Amy. Three things. First, there is a mistake in the way you are referring to the resolution field in your DCount:

[tblIssues.Resolution] should be
[tblIssues].[Resolution], but you don't need to qualify it at all, so just [Resolution] will be fine.

Second, is the type of resolution selected from your combo control a text value or a number? As you have it at present you are treating this value as a number. If it is text, you need to enclose the value in single quotes.

Third, the control reference is being provided to DCount as part of the WHERE string, and this will defer its interpretation until the DCount is run. This can fail, depending on where and when the DCount is run. It is normal to pass the current value of the control into the WHERE clause instead, as you will see in the final example below (treating the comparison as text).

Expand|Select|Wrap|Line Numbers
  1. countOfOccurrence: DCount("Resolution","tblIssues","[Resolution] = '" & Forms![subFormOccurrence].[drpResolution] & "'")
If the resolution really is a number, then you won't need the single quotes at all:

Expand|Select|Wrap|Line Numbers
  1. countOfOccurrence: DCount("Resolution","tblIssues","[Resolution] = " & Forms![subFormOccurrence].[drpResolution])
If you are referring to a control on a subform, the normal way to refer to the control is like this:

Forms![Your Main Form Name]![Subform Name].Form![Subform control name]

I note that this is not what you have posted above, and I did not include the full syntax in my examples to keep them brief. Keep this in mind when trying to resolve the issues mentioned above - you will need to use the correct syntax for retrieving the value of drpResolution or the Where clause will simply not work at all.

I don't know the name of your main form, so all I can give is an exampple of what might be needed, and you would need to substitute the actual name of your main form accordingly:

Expand|Select|Wrap|Line Numbers
  1. countOfOccurrence: DCount("Resolution","tblIssues","[Resolution] = '" & Forms![Your MainForm Name]![subFormOccurrence].Form![drpResolution] & "'")


-Stewart
Apr 9 '11 #2
Thank you, Stewart, that is exactly what I needed.
Apr 9 '11 #3

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

Similar topics

1
by: Tom Bean | last post by:
When a control is created during program execution, how can the control add itself to the form's control collection? I'd like to do this without the control or the form having to know specific...
7
by: Dave | last post by:
I have two forms, Form1 and Form2. From Form2, how do I reference the value in a control on Form1? Or perhaps a more specific question: Form1 contains a textbox with the value of 10. This form...
2
by: authorking | last post by:
How to access a control in another form and how to make a form become a MDI container.
3
by: Eh | last post by:
I have a project containing a WindowsForm and a module and need to set the text property on a label control on the form from the module. here's the code (from MS Framework .Net Doc): Dim test...
1
by: Jeff | last post by:
Hello All: I have recently upgraded to VB .Net 2003 from VB6 and am having a little trouble. I have a MDI parent form that has a frame on it with a list box on the frame. I open an MDI child...
15
by: http://www.visual-basic-data-mining.net/forum | last post by:
Does anyone have any idea how to transferring data from TextBox1 in form1 to textBox2 in form2..... That means after i fill in any data in textBox1 and click Next button... It will bring me to...
7
by: Neo | last post by:
I am trying to create a custom control, & in this control i need to access the form where this control is added. How can i do this. - I tried to accept a new parameter in the constructor of this...
5
by: lisa | last post by:
This is incredibly frustrating. I have a VB6 app at work that we're upgrading to .NET. In the VB6 code, I'm able to get a reference to txtText by using frm.Controls(txtText). In ASP.NET, we...
3
by: Darin | last post by:
I have a form that might (or might not) have a textbox on it named something particular - how can I find if the form has the control, and if it does what the text of the control has? This form has...
13
by: Just_a_fan | last post by:
I am adding a bunch of controls with the code below. Problem 1: When program flow passes to "UpperChanged" when I click it, the control name is undefined. When I enter: If udUpperLim1.Value 1...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.