Results 1 to 3 of 3
  1. #1
    Ace2014 is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    88

    Macro code: Automate Select Query Sequence

    Hi Everyone,



    So after the posts from my previous postCode help: Automate Select Qry with variable criteria inputted from a form

    I was feeling a little overwhelmed and down. But I've kept brainstorming processes I thought would work and be easy to use for Accessphobes lol

    I've decided on a new process. I'm looking for feedback as to if you think it'll work.
    I'm still lacking the coding experience to get it started.


    Objective:
    Accessing scope of data users are interested in extracting from a knowledge database (data mining interface)

    Process:
    Automation of Select Queries for users with little knowledge of Access

    Defining scope through by the segmentation:
    This segmentation combines relational data

    Code:
    Select Level 1 Data: form with a drop down box
    Run Select Query
    (I could have a table, "Level1" and it gets filled with the criteria. 
    There would be a select query also pre-made with this table linked to the market data query. 
    They would be linked 1 to many so when the select query ran, it would produce only the possible Level 2 options) 
    
    Prompt to select Level 2 Data: form with a drop down offering only Level 2 options in the Level 1 previously selected 
    Run Select Query
    (I could have a table, "Level2" and it gets filled with the criteria. 
    There would be a select query also pre-made with this table linked to the "Level 1" query. 
    They would be linked 1 to many so when the select query ran, it would produce only the possible Level 3 options) 
    
    Prompt to select Level 3 Data: form with a drop down offering only Level 3 options based off previous selections 
    Run Select Query
    (I could have a table, "Level 3" and it gets filled with the criteria. 
    There would be a select query also pre-made with this table linked to the "Level 2" query. 
    They would be linked 1 to many so when the select query ran, it would produce only the data on the same finest level) 
    
    
    Prompt to select Dates no older than X in format "mmm/year"
    or bypass to next criteria 
    or go directly to export data to excel (.xls or .xlsx)
    Run Select Query/Proceed to next criteria/Export
    (I could have a table, "Date" and it gets filled with the criteria. 
    There would be a select query also pre-made with this table linked to the "Level 3" query. 
    They would be linked 1 to many so when the select query ran, it would produce only the data on the same level with dates greater than X) 
    
    
    Prompt to select multiple datatypes in another criteria level (named Brand) from a drop down that only allows choices based off the previous selections
    or bypass to next criteria 
    or go directly to export data to excel (.xls or .xlsx)
    Run Select Query/Proceed to next criteria/Export
    (I could have a table, "Date" and it gets filled with the criteria. 
    There would be a select query also pre-made with this table linked to the "Date" query or Level 3 if Date was bypassed
    They would be linked 1 to many so when the select query ran, it would produce only the data on the same level with dates greater than X and specific Brands) 
    
    
    Prompt to select multiple datatypes in another criteria level (named Market) from a drop down that only allows choices based off the previous selections
    or bypass to next criteria 
    or go directly to export data to excel (.xls or .xlsx)
    Run Select Query/Proceed to next criteria/Export
    (I could have a table, "Brand" and it gets filled with the criteria. 
    There would be a select query also pre-made with this table linked to the "Brand" query, Date, or Level 3 depending on which data were bypassed, if bypassed
    They would be linked 1 to many so when the select query ran, it would produce only the data on the same level with dates greater than X, specific Brands, and specific markets) 
    
    
    After Export, clear tables
    I hope this will be possible!
    Thanks in advance

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    The replies to your previous thread holds all the answers, although it seems you need help to get started. This would be the VBA code required to build the SQL for the query.

    First, create the query in the usual way and fill in criteria as if each field on the form has an entry.
    Copy the SQL into VBA to use as your model (comment it out).
    In VBA, build the SQL using lots of "IF" statements such as IF L1<>"" then strSQL=strSQL & " AND L1='" & me!L1 & "'", etc - using the model as your basis.
    Once you have built the SQL string, use Debug.Print to display it, then copy it to an empty query and try to run it, that way you can get it right throught trial and error.

  3. #3
    Ace2014 is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    88
    Quote Originally Posted by aytee111 View Post
    The replies to your previous thread holds all the answers, although it seems you need help to get started. This would be the VBA code required to build the SQL for the query.

    First, create the query in the usual way and fill in criteria as if each field on the form has an entry.
    Copy the SQL into VBA to use as your model (comment it out).
    In VBA, build the SQL using lots of "IF" statements such as IF L1<>"" then strSQL=strSQL & " AND L1='" & me!L1 & "'", etc - using the model as your basis.
    Once you have built the SQL string, use Debug.Print to display it, then copy it to an empty query and try to run it, that way you can get it right throught trial and error.

    Great, thank you, that will definitely come in handy once I get started.

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

Similar Threads

  1. Replies: 12
    Last Post: 06-12-2014, 07:37 AM
  2. Need Code to Automate ImportExportSpreadsheets
    By Ace2014 in forum Programming
    Replies: 65
    Last Post: 06-12-2014, 06:43 AM
  3. Replies: 1
    Last Post: 05-07-2012, 08:21 AM
  4. Replies: 3
    Last Post: 01-02-2011, 07:17 PM
  5. Question on Macro to automate file import
    By delkath in forum Access
    Replies: 4
    Last Post: 05-25-2010, 04:28 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