Results 1 to 2 of 2
  1. #1
    gangel is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    194

    Allocating criteria to query with VBA

    Hi ppl,

    So ive been learning HEAPS about all this, and now im stuck on a new problem!
    So my dilemma:

    I have query... "alpha"
    and i columns "A", "B" and "C"



    I can criteria the fields to C = null and get all the queries where C has no value. (i understand this part)

    Now what i want to do in my report is to get 3 text boxes (labled "AValue" "BValue" and "Cvalue" on a form and if i want to see all results i have a command button that opens a rport based on query "alpha" where each value is that of the text boxes.

    Once again.. i get this. I can have the critera of each field in the query be the name of the text box.

    WHAT IF however i now have another text box on that same form (or a different form) and the number i put in those boxes is a .. "smaller than" value.

    So i now have 3 more boxes "SMLRTHANA" "SMLRTHANB" and "SMLRTHANC"
    So if you run THAT report based on the SAME query "alpha" it now uses > in the criteria.
    Should i infact have 2 separate queries and 2 separate boxes

    OR can i use the command button and VBA to allocate the criteria instead of the criteria being based inside the query itself??

    I hope ive made sense... i re-read it and i hope it sounds right!!!
    Thanks for any inputs ppl!

    Gangel

  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    in general terms; a query object has criteria in a field or fields. that criteria can be a 'call' from a textbox / control in an open form. As the value in that form's control changes - the query results dynamically change. one can also sometimes have the criteria along with a wild card value but that depends on the data and the type results you seek...

    but to change the criteria itself - such as applying to different fields - requires an entirely different approach where one dynamically builds an SQL statement in VB - and then running that sql as the report's record source or making a new temporary query object

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

Similar Threads

  1. allocating products into boxes
    By Pacific1 in forum Queries
    Replies: 28
    Last Post: 12-08-2014, 10:04 PM
  2. Replies: 1
    Last Post: 11-13-2014, 11:34 PM
  3. Replies: 4
    Last Post: 08-30-2014, 10:23 AM
  4. Replies: 5
    Last Post: 09-20-2012, 03:27 PM
  5. Replies: 5
    Last Post: 08-02-2012, 09:44 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