Results 1 to 11 of 11
  1. #1
    Star Lounger
    Join Date
    Apr 2001
    Location
    Oklahoma City, Oklahoma, USA
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print word based on field (A2K)

    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

  2. #2
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Print word based on field (A2K)

    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.
    Jerry

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print word based on field (A2K)

    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.

  4. #4
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Print word based on field (A2K)

    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
    Regards,

    Gary
    (It's been a while!)

  5. #5
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Print word based on field (A2K)

    ... 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
    Regards,

    Gary
    (It's been a while!)

  6. #6
    Star Lounger
    Join Date
    Apr 2001
    Location
    Oklahoma City, Oklahoma, USA
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print word based on field (A2K)

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

    JAM

  7. #7
    Star Lounger
    Join Date
    Apr 2001
    Location
    Oklahoma City, Oklahoma, USA
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print word based on field (A2K)

    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?

  8. #8
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Print word based on field (A2K)

    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
    Regards,

    Gary
    (It's been a while!)

  9. #9
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Print word based on field (A2K)

    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.
    Regards,

    Gary
    (It's been a while!)

  10. #10
    Star Lounger
    Join Date
    Apr 2001
    Location
    Oklahoma City, Oklahoma, USA
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print word based on field (A2K)

    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

  11. #11
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Print word based on field (A2K)

    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
    Regards,

    Gary
    (It's been a while!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •