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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Adams
    New Member
    • Jul 2010
    • 55

    #1

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

    What is the code for debugging a yes/no check box located in a table?

    I have tried the common
    Code:
    debug.print [[I]checkbox[/I]];
    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
    Code:
    debug.print [[I]textbox[/I]];
    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?
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    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)>

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      This is the Syntax I usually use in these circumstances:
      Code:
      Debug.Print IIf(Me![chkOne], "Yes", "No")
      P.S. - You may be getting the Error because the Check Box is not 'Bound'

      Comment

      • Michael Adams
        New Member
        • Jul 2010
        • 55

        #4
        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:
        Code:
        Debug.Print [Type]; IIf(Me![email], "yes", "no");

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          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.

          Comment

          • Michael Adams
            New Member
            • Jul 2010
            • 55

            #6
            I am executing this code within my case statement on a form for a click event

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              1. Click() Event for what Control?
              2. Kindly post the entire code segment.

              Comment

              • Michael Adams
                New Member
                • Jul 2010
                • 55

                #8
                Here is where the private sub is called:
                Code:
                Private Sub Sub_Cmd_Click()
                
                Call EmpAllWorkOrder
                    If Me.chkEmp.Value = -1 Then EmpAll
                        If Me.chkemail.Value = -1 Then EmpAllEmail
                            If Me.chkBnk.Value = -1 Then EmpAllBanks
                                If Me.chkDte.Value = -1 Then EmpAllDateRange
                                    If Me.chkVnd.Value = -1 Then EmpAllVendor
                                    
                
                End Sub
                This is the private sub:
                Code:
                Private Sub EmpAllEmail()
                
                Dim EAEcount As Integer
                
                Select Case Me.chkemail.Value
                    Case "-1"
                        EAEcount = DCount("[type]", "WorkOrderTracking", "[type]")
                        Debug.Print [Type]; IIf(Me![email], "yes", "no");
                        Me.TotalTxt.Value = EAEcount
                        Me.Repaint
                        EAEcount = DCount("[type]", "WorkOrderTracking", "[Type] = 'Incident'")
                        Me.Inc_Text.Value = EAEcount
                        Me.Repaint
                        EAEcount = DCount("[type]", "WorkOrderTracking", "[Type] = 'Request'")
                        Debug.Print [Type];
                        Me.Req_Text.Value = EAEcount
                        Me.Repaint
                        EAEcount = DCount("[type]", "WorkOrderTracking", "[Type] = 'Change Order'")
                        Debug.Print [Type];
                        Me.CO_Text.Value = EAEcount
                        Me.Repaint
                    Case Else
                        Select Case Me.chkemail.Value
                            Case "Incident"
                                EAEcount = DCount("[Type]", "workordertracking", "[type] = 'Incident'")
                                Me.Inc_Text.Visible = True
                                Me.Req_Text.Visible = False
                                Me.CO_Text.Visible = False
                                Me.chkWrA.Visible = False
                                Me.Inc_Text.Value = EAEcount
                                Me.TotalTxt.Visible = False
                            Case "Request"
                                EAEcount = DCount("[Type]", "workordertracking", "[type] = 'Request'")
                                Me.Inc_Text.Visible = False
                                Me.Req_Text.Visible = True
                                Me.CO_Text.Visible = False
                                Me.chkWrA.Visible = False
                                Me.Req_Text.Value = EAEcount
                                Me.TotalTxt.Visible = False
                            Case Else
                                EAEcount = DCount("[Type]", "workordertracking", "[type] = 'Change Order'")
                                Me.Inc_Text.Visible = False
                                Me.Req_Text.Visible = False
                                Me.CO_Text.Visible = True
                                Me.chkWrA.Visible = False
                                Me.CO_Text.Value = EAEcount
                                Me.TotalTxt.Visible = False
                        End Select
                End Select
                End Sub
                I am trying to find the value of the field on the workordertracki ng table so that I can put it in the criteria portion of the count.

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  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:
                  Code:
                  Select Case Me.chkemail.Value 
                    Case "Incident" 
                    Case "Request"
                  End Select

                  Comment

                  • Michael Adams
                    New Member
                    • Jul 2010
                    • 55

                    #10
                    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:
                    Code:
                    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.

                    Comment

                    • missinglinq
                      Recognized Expert Specialist
                      • Nov 2006
                      • 3533

                      #11
                      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.Val ue within a Select Case Me.chkemail.Val ue! 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)>

                      Comment

                      • ADezii
                        Recognized Expert Expert
                        • Apr 2006
                        • 8834

                        #12
                        Assuming [EMail] is a Yes/No Field in the WorkOrderTracki ng Table, then I see no reason why the following Statement will not work:
                        Code:
                        EAEcount = Dcount("[Type]", "WorkOrderTracking", "[Type] = 'Incident' and [EMail] = True")

                        Comment

                        • Michael Adams
                          New Member
                          • Jul 2010
                          • 55

                          #13
                          Thanks, that is exactly what I needed. "True" was the value I was looking for.

                          Thanks again.

                          Comment

                          Working...