Passing variable from table to query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jay Sarno

    Passing variable from table to query

    I have queries (4) that all use some form of date range to process segmenting a customers value. I use a format of YYYY-MM for 100% of these queries. I wrote all four queries to have user input to enter the dates and they all work perfectly well. What I want to do is automate process. I already have an information table that I use as visual hint for manually entering the proper dates. My question, can I use a form or table that essentially duplicates my information table to allow the query to pick up the proper YYYY-MM. If yes, I would greatly apprciate any help/code.
  • danp129
    Recognized Expert Contributor
    • Jul 2006
    • 323

    #2
    Do you just need to format the date? Such as msgbox(New Date(2010, 1, 1).ToString("yy yy-MM"))

    Or do you need a hashtable:
    Code:
            Dim DatesHashtable As New Hashtable
    
            'generate fake mock data for key=UserSubmittedDate, value=DateIWantToUseInstead
            DatesHashtable.Add("1/1/2010", "2010-01")
            DatesHashtable.Add("2/1/2010", "2010-01")
            DatesHashtable.Add("3/1/2010", "2010-01")
            DatesHashtable.Add("4/1/2010", "2010-02")
            DatesHashtable.Add("5/1/2010", "2010-02")
            DatesHashtable.Add("6/1/2010", "2010-02")
            DatesHashtable.Add("7/1/2010", "2010-03")
            DatesHashtable.Add("8/1/2010", "2010-03")
            DatesHashtable.Add("9/1/2010", "2010-03")
            DatesHashtable.Add("10/1/2010", "2010-04")
            DatesHashtable.Add("11/1/2010", "2010-04")
            DatesHashtable.Add("12/1/2010", "2010-04")
    
    
            Dim userValue As String = "6/1/2010"
            MsgBox("The date to enter for '" & userValue & "' is " & DatesHashtable(userValue))

    Comment

    Working...