Results 1 to 3 of 3
  1. #1
    aero is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    12

    Exclamation VBA or macro to conditionally run append query

    I am able to query the last two weeks and a local table of the remaining 2 years worth of data as to not bog down the server. The only way I idea I have come up with for doing this is to create an append query that acts conditionally on a query that determines whether the local table has the strings "yymmdd" of the last two report periods by comparing the results of two Max(report periods column)s for the selected ID. If they aren't equal, than the append query should append the most recent week or two of data to the local table. At this point I would base my pivot table and pivot chart off of only the the local table. The problem is, I don't know the vba to tell access to compare the result of the Max() functions from the two queries I run on the the local archive, and live table on the server. Can anyone help? There is also the issue that although their may be a value in the local table for the most current two weeks, it might be updated in the server based table. Then I might have to go about using an update query without knowing what the Primary ID of the last two weeks are, but that's a smaller issue and will be encountered less often. Anyone able to help????!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    On the button click , get the max date , put on form, then run the query to read the date off the form...

    Code:
    vDate = Max("[RunDate]",table)
    
    txtMaxDate = vDate
    docmd.openquery "qaAddRecords"       '
    'your append query will use the criteria for date on the form to pull the records....forms!frmMyForm!txtMaxDate
    'it is faster than using Max in the actual query.

  3. #3
    aero is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    12
    I'm not sure what you mean not to run the Max function in a query. If I do it the way you've written it it looks like it's running a max on one field in the table from the server because it will return the max date associated with all Respondent IDs rather than the one I have selected on my form. Currently I'm running a max query based on the selected ID on my form first. Does that not need to be done?

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

Similar Threads

  1. Update & Append queries - Macro question
    By noaccessguru in forum Macros
    Replies: 12
    Last Post: 08-29-2013, 06:00 AM
  2. Replies: 1
    Last Post: 01-16-2013, 10:58 AM
  3. Replies: 2
    Last Post: 05-05-2012, 02:34 AM
  4. Replies: 1
    Last Post: 10-06-2011, 08:37 AM
  5. Replies: 7
    Last Post: 07-21-2011, 01:01 PM

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