Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2010
    Posts
    186

    Unanswered: ACCESS 2007: Unbound Check box on a form to make selection

    Good morning! I am trying to add some syntax to a report that will allow the user to include fields or not.

    The record source of this report is a query, and there is parameter in there to select criteria on Saelsman(Name) I don't want to have to change this query because of it's parameter and the join I made in there........



    So after googling around some to research, my approach to this was to add an unbound checkbox (hidden) on the report, the control source being criteria =[Do you want to include notes?], triple state No



    Then I tried to select visibility on the fields with this event:

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If ([Check180] = True) Then
    Me.NDATE.Visible = True
    Me.NSUBMITTEDBY.Visible = True
    Me.NOTE.Visible = True
    Me.FOLLOWUPGOAL.Visible = True
    Else
    End If

    End Sub



    In report preview I am getting the prompt, and so I tried typing Y and N and Yes and No, etc. I get no errors, but the fields are there either way. So it seems to run (no errors) but does nothing.



    Can someone help me figure out what I am missing?

    1.) Is my checkbox trick right?

    2.) Do I have to make the detail secton and each field invisible on load so that this can decide whether to show them or not?

    3.) Am I showing the checkbox correctly in the code?



    Any insght will be appreciated!

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Normally the only valid answers should be 'True', 'False' or anything numeric ( 0 = False, everything else = True).

    You could achieve the same goal more logically like this:
    Code:
    Private Sub Report_Open(Cancel As Integer)
    
        If MsgBox("Do you want to include notes?", vbYesNo + vbQuestion) = vbYes Then
            Me.NDATE.Visible = True
            Me.NSUBMITTEDBY.Visible = True
            Me.NOTE.Visible = True
            Me.FOLLOWUPGOAL.Visible = True
        Else
            Me.NDATE.Visible = False
            Me.NSUBMITTEDBY.Visible = False
            Me.NOTE.Visible = False
            Me.FOLLOWUPGOAL.Visible = False
        End If
        
    End Sub
    Have a nice day!

  3. #3
    Join Date
    Jun 2010
    Posts
    186
    Perfect, it works! Except...I've got another loop to go around.
    The command button macro from the form that opens this report did 4 things - open report, run command - print, close report, close form

    I had to remove the print, close, close because the Report_Open event couldn't run. The report couldn't give me the message box.

    Now I need to figure out how to code the report to print (we print over a server, so my print command opens a print dialog box), close itself, then close the form that was left over. Any ideas?

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    1. In the procedure that opens the report, use:
    Code:
        Dim booShowComments As Boolean
        
        booShowComments = (MsgBox("Do you want to include notes?", vbYesNo + vbQuestion) = vbYes)
        DoCmd.OpenReport "<MyReport>", , , , , booShowComments
    2. In the report itself, use:
    Code:
    Private Sub Report_Open(Cancel As Integer)
    
        Me.NDATE.Visible = Me.OpenArgs
        Me.NSUBMITTEDBY.Visible = Me.OpenArgs
        Me.NOTE.Visible = Me.OpenArgs
        Me.FOLLOWUPGOAL.Visible = Me.OpenArgs
     
    End Sub
    Have a nice day!

  5. #5
    Join Date
    Jun 2010
    Posts
    186
    Terrific - and again - thank you!
    This code has done exactly what I'd like, except goes straight to the printer without allowing print options.
    I am unable to modify the print server for my location, so we've been relying on the print dialog box to select printer, and 2-side print.

    Is there a way to get it to open to print dialog box, and then close?

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You can use:
    Code:
    DoCmd.OpenReport "<MyReport>", acViewPreview , , , , booShowComments
    to open the report in preview mode.
    Have a nice day!

Posting Permissions

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