Results 1 to 11 of 11
  1. #1
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160

    With OR option in querry, when ever run asking for input of Variable

    Hi guys,



    I am having a query where BillNumber is passed from either a form or Report to a query to generate Bill (in report format). I have set up the query in which Bill Number is either passed from Form (text box input) or through report (from number of bills user can click of desired one). Both functions work fine, But whenever I am trying to pass the argument through Form (textbox), it ask me for the input of report, also pressing ENTER (with blank input) bypasses the problem but on first place it should not happen. The screen is quiet annoying. For your reference query is given below:

    SELECT tblSale.SaleDate, tblSale.Challan, tblSale.BillNumber, tblSale.Transport, tblSale.GRNumber, tblParties.PartyName, tblParties.Address, tblParties.City, tblParties.State, tblParties.GSTNo, tblParties.StateCode, tblSale.InvoiceAmt, tblSale.InvCGST, tblSale.InvSGST, tblSale.InvIGST, tblSale.FinalAmt, tblSale.Freight, tblSale.ReverseCharges, tblSale.RoundingOff, tblSale.GrandTotal, tblSale.ReverseCharge, tblSale.InvoiceType, tblSale.EComm, tblSale.Cess, tblParties_1.PartyName, tblParties_1.Address, tblParties_1.City, tblParties_1.State, tblParties_1.GSTNo, tblParties_1.StateCode
    FROM tblParties INNER JOIN (tblSale INNER JOIN tblParties AS tblParties_1 ON tblSale.ShipToID_FK = tblParties_1.BuyerID_PK) ON tblParties.BuyerID_PK = tblSale.BuyerID_FK
    WHERE (((tblSale.BillNumber)=[Forms]![PrintBill]![BillNum] Or (tblSale.BillNumber)=[Reports]![rptBills1Criteria]![BillNumber]));

    I can always create a separate query, But want to fix this one & learn my mistake.

    Thanks for your help.
    Regards
    Deepak Gupta

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Since you're opening a report you could take the criteria out of the query and use this method:

    http://www.baldyweb.com/wherecondition.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    The report should really use the calling form as the controlling element, not something in the report itself.
    Or use a where condition as Paul has suggested.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    Dear Minty,

    I have used calling from form only (It worked perfect). Then added function to search records and then do the calling through report as Paul Suggested, did that and it worked perfectly. Now When I am calling through search fuction works fine no issues but when uses form with direct user input, query asks for report's function input WHY? when in query I have given criteria with OR function why ask for the input if one is met. That is what my problem is.

    Hope I HAve been able to explain my problem.

    Regards
    Deepak Gupta

  5. #5
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    I think I understand your question.
    Even though you have the OR the query will always ask for both parameters, it has to, to be able to evaluate the expression, regardless of it being needed or not.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    yes that is my question why asking for the parameter for second option when in OR query.

    Regards
    Deepak Gupta

  7. #7
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    Because it has to. A queries parameters aren't optional.
    The only way around it would be to use something like this in the criteria

    Code:
    IIf(IsNull([Reports]![rptBills1Criteria]![BillNumber]),"*",[Reports]![rptBills1Criteria]![BillNumber])
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    Not Working, first asks for the parameter and then gives error Equation too long, closing all macros.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If that's intended to test for the object being open, testing for Null won't work. Perhaps:

    http://www.theaccessweb.com/forms/frm0022.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    Quote Originally Posted by pbaldy View Post
    If that's intended to test for the object being open, testing for Null won't work. Perhaps:

    http://www.theaccessweb.com/forms/frm0022.htm
    Doh, no of course it won't.

    @OP - you can't do what you want without some VBA trickery as explained in the linked item.
    In which case you may as well just run one of two queries based on the forms being actually loaded anyway.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  11. #11
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    Hi guys,

    Thanks for all the help. Could find out how to rectify the issue. I have worked out a way around but not very convincing one.

    Thanks anyway for all your help and guidance.
    Regards
    Deepak gupta

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

Similar Threads

  1. Query with variable number of input parameters
    By keith2511 in forum Queries
    Replies: 16
    Last Post: 05-18-2018, 06:17 PM
  2. Replies: 2
    Last Post: 09-01-2015, 02:57 AM
  3. Replies: 2
    Last Post: 02-16-2013, 04:32 PM
  4. Can I have an input variable in a field formula
    By FeatherDust in forum Queries
    Replies: 3
    Last Post: 09-20-2009, 06:40 PM
  5. Replies: 1
    Last Post: 05-20-2009, 06:15 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