Results 1 to 4 of 4
  1. #1
    Seven is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2009
    Posts
    8

    using forms control as report variable

    I am trying to run a report using a form's control value as a query variable but cannot seem to get it to work. Specifically, I need to be able to return all of the records if the forms control is empty, but get no records.

    this is not exact as I dont have access at this computer, but hopefully close enough for someone to help.



    query

    Iif([Forms]![MyForm]![MyControl],NULL,[Forms]![MyForm]![MyControl])

    I thought it would look like this in the query...

    if the control has a value, then use the value of the control as the query parameter (and only return the records that match the control's value), otherwise, use NULL as the query parameter (meaning to return all of the records, regardless of the control's value)


    any help here is greatly appreciated.

  2. #2
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    Add a new column in your report recordsource and enter this ([FIELD NAME] needs to be replaced with the field name in your db you are filtering against):

    IIf(IsNull([forms]![MyForm]![MyControl]),([FIELD NAME]) Like "*" Or ([FIELD NAME]) Is Null,([FIELD NAME])=[forms]![MyForm]![MyControl])

    Then in the criteria put:

    <> False

  3. #3
    Seven is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2009
    Posts
    8
    thanks a million. I will check this out at work on monday!

  4. #4
    Seven is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2009
    Posts
    8
    Excellent! thanks again for the assist!

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

Similar Threads

  1. binding report field to variable
    By frente in forum Reports
    Replies: 1
    Last Post: 10-19-2009, 02:48 AM
  2. Passing SQL result into variable
    By jonny in forum Access
    Replies: 3
    Last Post: 10-18-2009, 07:46 AM
  3. Variable Criteria
    By JamesLens in forum Queries
    Replies: 0
    Last Post: 01-02-2009, 04:55 PM
  4. Variable question
    By synapse5150 in forum Programming
    Replies: 1
    Last Post: 07-09-2008, 08:17 AM
  5. Sending control to specific control
    By wasim_sono in forum Programming
    Replies: 2
    Last Post: 04-19-2007, 08: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