Results 1 to 3 of 3
  1. #1
    morrishelo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2018
    Posts
    2

    Question Changing the criteria of a query depending on a form

    I have a query that is using a form named "DateRange2" to change the criteria of one field "Dept1" in order to filter this query. Then the I designed a report that can be opened by using a command button 'cmdOpenReport' with form VBA code:

    Option Compare DatabasePrivateSub Form_Open(Cancel AsInteger)
    Me.Caption =Me.OpenArgs
    EndSub
    PrivateSub cmdOpenReport_Click()

    If IsNull([SrchDateFrom])Or IsNull([SrchDateTo])Then

    MsgBox
    "Please enter your date range.", _
    vbInformation
    + vbOKOnly,"No Date Range!"
    DoCmd
    .GoToControl "SrchDateFrom"
    Else
    If [SrchDateFrom] > [SrchDateTo] Then
    MsgBox
    "Date 'To' Value is earlier that Date 'From', please enter logic date range.", _
    vbInformation
    + vbOKOnly,"Illogic Date Range!"
    DoCmd
    .GoToControl "SrchDateFrom"
    Else
    Me.Visible =False

    EndIf
    EndIf
    EndSub



    And My question is: How to to change the criteria of a query depending on a form? to show only the entries of the selected department; however, in case of NO department is selected, then I want the report to show all the entries!
    Adding that; when I manually set the criteria to: Like [Forms]![DateRange2]![SrchDept] & "*", then it shows all the entries. But alternatively when I set the criteria to: [Forms]![DateRange2]![SrchDept], then it shows the selected department only. However, this doesn't solve my problem because I actually want to shift between the two cases by using the form named "DateRange2".
    Please help me in a very simple way as I am just a beginner.

    Also I was trying something like:
    Expr1: IIf(IsNull([Forms]![DateRange2]![SrchDept]), [Correspondence]![Dept1] = Like ([Forms]![DateRange2]![SrchDept]) & "*",[Correspondence]![Dept1] =([Forms]![DateRange2]![SrchDept])),
    but this doesn't work with me!

    Please help me!


  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,901
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    morrishelo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Mar 2018
    Posts
    2
    Dear @june7,
    Thank you for your review and response.
    Regards,

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

Similar Threads

  1. Replies: 1
    Last Post: 04-28-2015, 07:08 AM
  2. Replies: 1
    Last Post: 09-04-2014, 10:13 AM
  3. Replies: 3
    Last Post: 07-25-2013, 05:19 PM
  4. Changing Query Criteria from Form
    By dvgef2 in forum Queries
    Replies: 4
    Last Post: 06-24-2013, 12:14 PM
  5. Replies: 0
    Last Post: 03-16-2006, 04:59 AM

Tags for this Thread

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