Results 1 to 3 of 3
  1. #1
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287

    Editing queries criteria with VBA

    Hey guys,

    My company runs a contest about twice a month. I have built a program that figures out the winners. Our 2nd contest of the month has just started, but we still need access to the results of the first contest. I have a form that the accounting department uses to run the program. We have decided that they need to have quick access to the past 3 contests, and the current one. I know I can easily do this by duplicating the program and setting the date range different on each one. I'd rather be smarter about this. I have 4 buttons side by side on the form, each labeled with the date range. What I want to happen is having VB run to edit the date range in the SQL of the first query to input the desired date range. Here is the code of the query that needs to be changed:



    Code:
    SELECT SALES_SO.SO_WR_DT, SALES_SO.SO_STORE_CD, SALES_SO.DEL_DOC_NUM, SALES_SO.SO_EMP_SLSP_CD1, SALES_SO.SO_EMP_SLSP_CD2, SALES_SO.STAT_CD, SALES_SO.FINAL_DT, SALES_SO.CUST_CD, SALES_SO_LN.ITM_CD, INV_ITM.DES, SALES_SO_LN.UNIT_PRC AS RET_PRC, SALES_SO_LN.QTYFROM (SALES_SO INNER JOIN SALES_SO_LN ON SALES_SO.DEL_DOC_NUM = SALES_SO_LN.DEL_DOC_NUM) INNER JOIN INV_ITM ON SALES_SO_LN.ITM_CD = INV_ITM.ITM_CD
    WHERE (((SALES_SO.SO_WR_DT) Between #10/5/2013# And #11/1/2013#) AND ((INV_ITM.MNR_CD)="8900") AND ((SALES_SO_LN.VOID_DT) Is Null))
    ORDER BY SALES_SO.DEL_DOC_NUM;
    Thoughts?

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    You can use a click event to change the form's recordsource.

    Update the Where clause using variables declared as Date data type. The variable would equal your data picker. Date pickers should be unbound controls.

    something like

    Me.recordsource = strSQL

    where strSQL = the entire SQL including the dynamic WHERE clause

  3. #3
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    Simply add an 'Event ID' as a field to each record.... all Contest 1 entries should include "1" in that field, then reset that to be equal to "2" for the second contest... One technique is to manipulate the default value at the table level, at the form level..... or another technique would be to autostamp the actual date if your contests can be defined & segregated by date range ......

    This allows for a simple uniform structure. One can easily query based on that Event ID to isolate any contest at any time. Having separate DBs or separate record sources (tables) per contest would not be a good design......

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

Similar Threads

  1. Replies: 3
    Last Post: 10-19-2013, 10:21 AM
  2. Replies: 5
    Last Post: 09-12-2012, 09:53 AM
  3. Editing data from multiple queries
    By MHernan1 in forum Queries
    Replies: 2
    Last Post: 08-16-2012, 05:01 PM
  4. Queries Criteria with date
    By dssrun in forum Queries
    Replies: 4
    Last Post: 04-21-2011, 12:50 PM
  5. crosstab queries (criteria) won't work
    By Rich P in forum Queries
    Replies: 1
    Last Post: 02-15-2011, 10:53 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