• Print word based on field (A2K)

    Author
    Topic
    #375765

    I have a form with check boxes, when the report prints I need the word “YES” if checked and “NO” if not checked. How do I do this?

    I also have, on the same form, six check boxes at the bottom. If checked they need to cause a different report to print for each. I can do this with numerous queries and Macros but this is not very efficient and I would like to code it instead. If anyone could help me with this. I named the fields frm1, frm2, etc.

    I am trying to learn to code and can do some things, I bought Mastering Access 2000 by Simpson and Robinson but it is sparse with code examples and the ones in it are directed to specific tasks only. A long time ago, 10 years or so, I used to code dBase III extensively, but Access is much more logical and I do not know the ‘Language’ it speaks.

    Any help, Please annotate the example so I can learn, would be appreciated.

    Jail Administrator Medical
    JAM

    Viewing 2 reply threads
    Author
    Replies
    • #612834

      I’ve been looking at your idea of the ticks and thought about the idea of using an option group which can be run using the conditions in macros

      How about putting in 6 option buttons within an option group and give them the individual values of 1,2,3,4,5,6. Create a command button running your macro.

      The macro could run so that if optgrp[yourname] = 1 then print rpt1

      if optgrp[yourname] = 2 then print rpt2

      etc etc

      It is another way of getting around without relying on VBA.

    • #612858

      If you want a boolean field to display as Yes/No instead of a check box, put an unbound text box on the report. Then, bind the text box to the field (set the control source to the name of the field), and set the Format property to Yes/No.

      • #612945

        Thank You very much. This does exactly what I need for the Printing of the Yes and No.

        JAM

    • #612936

      To get a checkbox to print a report, place the following code in the on click event for the checkbox

      DIM stDocName as string
      If Forms!FormName!CheckName.Value = True Then
      stDocName = “Report Name”
      DoCmd.OpenReport stDocName, acPreview
      End If

      FormName is the name of the active form where the checkboxes are located
      CheckName is the name of the checkbox (ie. Check94 would be Check94.value)
      “Report Name” is the name of the report to open

      HTH

      • #612938

        … An update to my last post. The If statement isn’t really needed, I used that for printing multiple checked reports via a command button.

        The code below is better….

        DIM stDocName as string
        stDocName = “Report Name”
        DoCmd.OpenReport stDocName, acPreview

        • #612952

          This is very helpful, and I even understand what the code is doing, but how would I go about clicking more than one box and having the reports print out on close of the record instead of ever time I click, or unclick, the field?

          • #613087

            To print multiple reports, on your form set up all of the checkboxes that you need; one for each report. Do not put any code in the on click event of the checkboxes. The checkboxes will just allow the user to select a report.

            Add a command button to the form. On the on click event of the command button, put the code I supplied in the prior post with the If Then statements. When you click the command button which you could label as print reports, the if then statements will be evaluated. Any that evaluate to yes indicating a checkbox is checked will cause the report to print. If not checked, the report will not print. Basically, on the on click event of the command button you will have numerous if then statements or you could use a Case statement to determine if the checkboxes are checked and printed.

            HTH

          • #613088

            One last item, you said you wanted to print on close of a record. I do not understand what you mean, please clarify. You could put the code on an on close event of the form or somewhere else or on an after update event, etc.

            • #613101

              I see, It seems to work now, but what is the Case statement.

              When the data is accepted from the form and the user clicks on the close button I want it to run. But with what you sent me I think I am able to get it done. Thank You.

              JAM

            • #613512

              The Case statement is actually a Select Case… Just another way of doing the If, Then statements.

              … To open the reports on the on-close event, put the code (i.e, If Then statements) on the On-close event of the form. As I don’t typically run reports on the on-close event of a form, I am not sure if you will have any problems if the report data are based on any of the form elements. The report may try to reference data linked to the form that is closed.

              HTH

    Viewing 2 reply threads
    Reply To: Print word based on field (A2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: