Results 1 to 5 of 5
  1. #1
    SFC is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    47

    Macro help


    Can anyone help me with a macro or code. I have a text box in a form and a check box next to the text box. I would like to use the check box to determine if the contents of the text box will print. So if the check box is checked (True) then what ever is in the text box will print otherwise if not checked then it does not print.

    Is a marco the best way to do this? If so can anyone point me in the right direction.

    Thank you,
    Steve

  2. #2
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    If the form is going to remain open when the report opens, you could just add an expression into either the report's recordsource query or as a field on the report itself. The expression in the query or as the control source of a field on the report might look like this: =IIF(Forms!MyFormName!MyCheckBoxName = True,[myTextBoxFieldName],"") where [myTextBoxFieldName] is actually a field in the table... or =IIF(Forms!MyFormName!MyCheckBoxName = True,Forms!MyFormName!myTextBoxFieldName,"") if you want to specifically grab what is the value of the textbox on the form.

  3. #3
    SFC is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    47
    Thank you pkstormy for taking the time to reply, I'll give it a try!

  4. #4
    SFC is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    47
    Hi pkstormy,
    I'm trying to add your info into my report but having a little trouble becuse of my in experience, maybe you can help me.
    In my report I have a text field "Note-1", this text field currently shows what is in the form text boxt with this control source; =[Forms]![Form1]![Note1])

    I tried adding the expression you offered like this; =[Forms]![Form1]![Note1]=IIf([Forms]![Form1]![CheckNote1]=False,[Note-1],"")

    This gets flagged by Access and states "Invalid Control Property: Control Source" and "Circular reference"

    So when I do a print preview of the report when the check box is true the Note-1 field displays "0".
    When the check box is false it displays "#Type!"

    I will continue to try to work it out but if you have any more comments that would be great!

    Thanks,
    Steve

  5. #5
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Quote Originally Posted by SFC View Post
    Hi pkstormy,
    I'm trying to add your info into my report but having a little trouble becuse of my in experience, maybe you can help me.
    In my report I have a text field "Note-1", this text field currently shows what is in the form text boxt with this control source; =[Forms]![Form1]![Note1])

    I tried adding the expression you offered like this; =[Forms]![Form1]![Note1]=IIf([Forms]![Form1]![CheckNote1]=False,[Note-1],"")

    This gets flagged by Access and states "Invalid Control Property: Control Source" and "Circular reference"

    So when I do a print preview of the report when the check box is true the Note-1 field displays "0".
    When the check box is false it displays "#Type!"

    I will continue to try to work it out but if you have any more comments that would be great!

    Thanks,
    Steve

    You combined the two examples (one example was: =[Forms]![Form1]![Note1] - for retrieving the value from the form (and will be the same for every record)) and the other example was: MyExpressionFieldAnyThingIWantToNameIt: IIf([Forms]![Form1]![CheckNote1]=False,[Note-1],"") - for setting it up as an expression in a query in the recordsource (for grabbing the [Note-1] value from the table).

    Your code which is: =[Forms]![Form1]![Note1] should work if you want the same note for all records on the report. If you need to grab the value from the database table, then use the expression example in the recordsource query and then you'll see the expression name in the report design where it shows the fields. You just drag the expression in listing to the report where you want it.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Recording your own Macro
    By sabre1 in forum Access
    Replies: 1
    Last Post: 03-02-2011, 06:43 AM
  2. Replies: 0
    Last Post: 01-12-2011, 12:43 PM
  3. VBA Macro
    By DSTR3 in forum Access
    Replies: 1
    Last Post: 11-30-2010, 11:42 AM
  4. Need help with macro
    By abc123 in forum Programming
    Replies: 6
    Last Post: 06-13-2010, 12:34 AM
  5. MACRO help please
    By DianeG in forum Forms
    Replies: 2
    Last Post: 04-20-2010, 07:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums