By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,627 Members | 1,870 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,627 IT Pros & Developers. It's quick & easy.

How do I debug.print a yes/no check box....

Michael Adams
P: 55
What is the code for debugging a yes/no check box located in a table?

I have tried the common
Expand|Select|Wrap|Line Numbers
  1. debug.print [checkbox];
and what I get is a "Run-time error '2465' Microsoft Office Access can't find the field'|' referred to in your expression." No matter what checkbox field name I use it returns the same error. However, when I use the same code for a text field
Expand|Select|Wrap|Line Numbers
  1. debug.print [textbox];
a value for the field is returned.

What am I doing wrong or right, what do I need to do for this thought to work?
Aug 4 '10 #1

✓ answered by ADezii

Assuming [email] is a Yes/No Field in the WorkOrderTracking Table, then I see no reason why the following Statement will not work:
Expand|Select|Wrap|Line Numbers
  1. EAEcount = Dcount("[Type]", "WorkOrderTracking", "[Type] = 'Incident' and [email] = True") 

Share this Question
Share on Google+
12 Replies


missinglinq
Expert 2.5K+
P: 3,532
Assuming that checkbox is actually the name of a checkbox control on your form it should work.

But your statement
What is the code for debugging a yes/no check box located in a table?
makes me wonder if this is actually the case.

Linq ;0)>
Aug 4 '10 #2

ADezii
Expert 5K+
P: 8,703
This is the Syntax I usually use in these circumstances:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print IIf(Me![chkOne], "Yes", "No")
P.S. - You may be getting the Error because the Check Box is not 'Bound'
Aug 4 '10 #3

Michael Adams
P: 55
By using your code, the error is now telling me that it can not find the field that I am looking for. It is acting like the field doesn't exist in the table I am looking at. I also did a link table update before and after the code.

This is what the code looks like:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print [Type]; IIf(Me![email], "yes", "no");
Aug 4 '10 #4

ADezii
Expert 5K+
P: 8,703
Where exactly are you executing this code from, since the Syntax is correct in the proper context. The proper context that I am referring to is from within an Open Form and referring to a Field on it. You simply cannot refer to a Field in a Table otherwise in this manner.
Aug 4 '10 #5

Michael Adams
P: 55
I am executing this code within my case statement on a form for a click event
Aug 4 '10 #6

ADezii
Expert 5K+
P: 8,703
  1. Click() Event for what Control?
  2. Kindly post the entire code segment.
Aug 4 '10 #7

Michael Adams
P: 55
Here is where the private sub is called:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Sub_Cmd_Click()
  2.  
  3. Call EmpAllWorkOrder
  4.     If Me.chkEmp.Value = -1 Then EmpAll
  5.         If Me.chkemail.Value = -1 Then EmpAllEmail
  6.             If Me.chkBnk.Value = -1 Then EmpAllBanks
  7.                 If Me.chkDte.Value = -1 Then EmpAllDateRange
  8.                     If Me.chkVnd.Value = -1 Then EmpAllVendor
  9.  
  10.  
  11. End Sub
This is the private sub:
Expand|Select|Wrap|Line Numbers
  1. Private Sub EmpAllEmail()
  2.  
  3. Dim EAEcount As Integer
  4.  
  5. Select Case Me.chkemail.Value
  6.     Case "-1"
  7.         EAEcount = DCount("[type]", "WorkOrderTracking", "[type]")
  8.         Debug.Print [Type]; IIf(Me![email], "yes", "no");
  9.         Me.TotalTxt.Value = EAEcount
  10.         Me.Repaint
  11.         EAEcount = DCount("[type]", "WorkOrderTracking", "[Type] = 'Incident'")
  12.         Me.Inc_Text.Value = EAEcount
  13.         Me.Repaint
  14.         EAEcount = DCount("[type]", "WorkOrderTracking", "[Type] = 'Request'")
  15.         Debug.Print [Type];
  16.         Me.Req_Text.Value = EAEcount
  17.         Me.Repaint
  18.         EAEcount = DCount("[type]", "WorkOrderTracking", "[Type] = 'Change Order'")
  19.         Debug.Print [Type];
  20.         Me.CO_Text.Value = EAEcount
  21.         Me.Repaint
  22.     Case Else
  23.         Select Case Me.chkemail.Value
  24.             Case "Incident"
  25.                 EAEcount = DCount("[Type]", "workordertracking", "[type] = 'Incident'")
  26.                 Me.Inc_Text.Visible = True
  27.                 Me.Req_Text.Visible = False
  28.                 Me.CO_Text.Visible = False
  29.                 Me.chkWrA.Visible = False
  30.                 Me.Inc_Text.Value = EAEcount
  31.                 Me.TotalTxt.Visible = False
  32.             Case "Request"
  33.                 EAEcount = DCount("[Type]", "workordertracking", "[type] = 'Request'")
  34.                 Me.Inc_Text.Visible = False
  35.                 Me.Req_Text.Visible = True
  36.                 Me.CO_Text.Visible = False
  37.                 Me.chkWrA.Visible = False
  38.                 Me.Req_Text.Value = EAEcount
  39.                 Me.TotalTxt.Visible = False
  40.             Case Else
  41.                 EAEcount = DCount("[Type]", "workordertracking", "[type] = 'Change Order'")
  42.                 Me.Inc_Text.Visible = False
  43.                 Me.Req_Text.Visible = False
  44.                 Me.CO_Text.Visible = True
  45.                 Me.chkWrA.Visible = False
  46.                 Me.CO_Text.Value = EAEcount
  47.                 Me.TotalTxt.Visible = False
  48.         End Select
  49. End Select
  50. End Sub
I am trying to find the value of the field on the workordertracking table so that I can put it in the criteria portion of the count.
Aug 4 '10 #8

ADezii
Expert 5K+
P: 8,703
In general, your code needs to be rewritten, but first of all, if chkEMail is a Check Box which will return a True/False, Yes/No, On/Off Value, the Select Case Statement then makes no sense, namely:
Expand|Select|Wrap|Line Numbers
  1. Select Case Me.chkemail.Value 
  2.   Case "Incident" 
  3.   Case "Request"
  4. End Select
Aug 4 '10 #9

Michael Adams
P: 55
That is because there is a lot more going on than what you are seeing here. You are seeing only a piece of fruit to the entire cherry pie.
My main problem is that I am trying to return a value in my debug.print so that I can put the proper code within the 'criteria' portion of the dcount.
What will happen in the end is that I will have a statement that will look like this:
Expand|Select|Wrap|Line Numbers
  1. EAEcount = Dcount("[Type]", "WorkOrderTracking", "[Type] = 'Incident' and [email] = '-1'")
However, and this is where the problem lies---I do not know what value to put for the [email] field because Access is not recognizing the field[email]. If it did then I would not be having this trouble. I am trying to figure out the field name and the value of that field.
Aug 4 '10 #10

missinglinq
Expert 2.5K+
P: 3,532
Actually, as ADezii has suggested, you have a lot more going on besides Access not recognizing [email]! As he also said, everything here really needs to be scrapped and redone.

First off, there's no reason to have a Select Case Me.chkemail.Value within a Select Case Me.chkemail.Value! This makes absolutely no sense.

Secondly, if chkemail is, in fact, a checkbox, neither "-1", "Incident" nor "Request" are valid as Values. For a checkbox in VBA the valid choices would be 0/-1 or True/False. You'll notice that none of these valid Values have quotes around them.

As to Access not recognizing [email], is it a checkbox control on your form, or is the control actually named chkemail?

Linq ;0)>
Aug 4 '10 #11

ADezii
Expert 5K+
P: 8,703
Assuming [email] is a Yes/No Field in the WorkOrderTracking Table, then I see no reason why the following Statement will not work:
Expand|Select|Wrap|Line Numbers
  1. EAEcount = Dcount("[Type]", "WorkOrderTracking", "[Type] = 'Incident' and [email] = True") 
Aug 4 '10 #12

Michael Adams
P: 55
Thanks, that is exactly what I needed. "True" was the value I was looking for.

Thanks again.
Aug 4 '10 #13

Post your reply

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