Results 1 to 3 of 3
  1. #1
    janel is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Posts
    2

    Input dates and provide corresponding information from table

    Hello,

    I have a tasks database that I've setup and would like to be able to have a user input two dates (Datefrom and Dateto), click Submit, and provide the user with a query based on those dates from our task list table.

    I have a home screen which has a button for "Tasks Due Between Two Dates" and it pops up a small form called DateRange that has a choose your date range, with one field "Datefrom" and another field "Dateto". It has a Submit button on it. I have input masking for the date fields so the user knows what format to input the dates as.

    The table I want to be able to query off of is called "ITSD Self Assessment Tasks"

    On click, I want to close the DateRange form, run the query and show the results.

    I am completely lost as to how to pass the Datefrom and Dateto parameters chosen by the user through a query to the table.

    here's the random gobbledegook I have so far for the on-click action for the Submit button. I know it's crap.:

    Private Sub SubmitDates_Click()
    Dim datefrom As Date
    Dim Dateto As Date
    Let datefrom = Me.datefrom.Value
    Let Dateto = Me.Dateto.Value

    strSQL = "SELECT * FROM [ITSD Self Assessment Tasks] WHERE [Due Date] <= Me.Dateto And [Due Date] >= Me.datefrom"

    CurrentDb.Execute strSQL

    End Sub


    So, please, help!

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Lets try:

    Code:
    Private Sub SubmitDates_Click()
    Dim datefrom As Date
    Dim Dateto As Date
    Set datefrom = Me.datefrom
    Set Dateto = Me.Dateto
     
    strSQL = "SELECT * FROM [ITSD Self Assessment Tasks] WHERE [Due Date] <= "  & Dateto & " And [Due Date] >= " & datefrom ";"
     
    CurrentDb.Execute strSQL
     
    End Sub
    Notice the concatenation using &. Read up on that for more information. Also, its "Set", not "Let". Finally, There is no need to use Me. when using a declared variable. datefrom will suffice. Although, you can simply get rid of it and Use Me.dateFrom. the .Value is implied in VBA (I take it you come from a VB background)

  3. #3
    janel is offline Novice
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Posts
    2

    Compile Error

    Hi Shabz, thanks for the help.

    I'm getting a compile error: Object required. It highlights the Set Datefrom = Me.Datefrom line. For giggles I set it back to Let instead of Set, as that's seemed to work in my previous events. Then recompiled and now I get a Compile Error: Syntax Error, highlighting the last line, specifically the ";" portion at the end of your line.

    strSQL = "SELECT * FROM [ITSD Self Assessment Tasks] WHERE [Due Date] <= " & Dateto & " And [Due Date] >= " & Datefrom ";"

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

Similar Threads

  1. Replies: 2
    Last Post: 08-01-2010, 10:35 PM
  2. generic information for table population
    By TheShabz in forum Access
    Replies: 3
    Last Post: 04-25-2010, 10:40 PM
  3. How to Provide datalocking in Access 2003 db
    By Progress2007 in forum Database Design
    Replies: 1
    Last Post: 12-02-2009, 09:31 AM
  4. Replies: 4
    Last Post: 09-03-2009, 02:01 PM
  5. Replies: 0
    Last Post: 12-11-2006, 04:55 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