Results 1 to 8 of 8
  1. #1
    MDAO is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    20

    MS Access -- In a query, show a date that has been entered in a form?







    Hi all,

    I don't know much about MS Access, but I am using it more often recently at work as needed. This is the issue I am dealing with at the moment.

    I have created a query that shows some of the data from a database. I've also created a form to open the query. In the form I put on two text-boxes to enter dates, and only the data between them will show. Everything works fine, but I want to create two columns in the query, each of them showing one of the dates I enter in the form. I was just wondering if anyone has the solution to this.

    P.S.: Before I upgraded my MS Access from 2003 to 2007, I used to be able to do it by creating a column that says this "Begin Date: [Forms]![data_sorting]![begindate]" in the design view of the query. Now it doesn't work anymore.

    Thank you!

    Mike

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You can still do that. Are the date textboxes in the form header section?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    MDAO is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    20
    Quote Originally Posted by June7 View Post
    If you want to provide db for analysis, follow instructions at bottom of my post.
    Oh, I wrongly put them into the page header instead of the form header. That's why the textboxes didn't show. Now, they show in the form, and are referenced for the criteria. However, the dates still don't show in the column of the query.
    The debugging looks very complicated to me. I think I may need some time to chew. @@

  4. #4
    MDAO is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    20
    Which code should I debug? There is no VBA code for the query. There is only SQL, and it is like this:

    SELECT [Forms]![data_sorting]![begindate] AS FROM, [Forms]![data_sorting]![enddate] AS TO,
    WHERE (((Datebase_PCF.QDATE) Between [Forms]![data_sorting]![begindate] And [Forms]![data_sorting]![enddate]));

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    FROM is a reserved word, it has special meaning to SQL, use another name, like DateFrom and DateTo. Need FROM clause in the SQL, must refer to a table or query. Don't you want some other fields in the query?

    SELECT *, [Forms]![data_sorting]![begindate] AS DateFrom, [Forms]![data_sorting]![enddate] AS DateTo
    FROM Datebase_PCF
    WHERE (((Datebase_PCF.QDATE) Between [Forms]![data_sorting]![begindate] And [Forms]![data_sorting]![enddate]));
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    MDAO is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    20
    Quote Originally Posted by June7 View Post
    FROM is a reserved word, it has special meaning to SQL, use another name, like DateFrom and DateTo. Need FROM clause in the SQL, must refer to a table or query. Don't you want some other fields in the query?

    SELECT *, [Forms]![data_sorting]![begindate] AS DateFrom, [Forms]![data_sorting]![enddate] AS DateTo
    FROM Datebase_PCF
    WHERE (((Datebase_PCF.QDATE) Between [Forms]![data_sorting]![begindate] And [Forms]![data_sorting]![enddate]));
    There is a lot of Chinese names in there, so I skipped the unrelated content to make it less confusing.
    I tried opening a new query with only the code your provided, but the dates still don't show. Something is funny though. You know how it will pop up a window when you run a query if one or more of the columns has a name that can't be sourced? If I enter the dates in those windows, they will show in my query. They just don't when the dates are referenced from the textboxes in my form.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I cannot replicate the issue. It works for me.

    The filter criteria referencing the textboxes as parameters works?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    MDAO is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2014
    Posts
    20
    Quote Originally Posted by June7 View Post
    I cannot replicate the issue. It works for me.

    The filter criteria referencing the textboxes as parameters works?
    It used to work for me too. =[
    Yes, the filter works. So odd...

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

Similar Threads

  1. Form won't show entered records
    By FMAlanbrooke in forum Forms
    Replies: 4
    Last Post: 09-16-2014, 08:38 PM
  2. Show The Last 10 Records entered on Form
    By athyeh in forum Forms
    Replies: 2
    Last Post: 11-28-2013, 09:51 AM
  3. Replies: 12
    Last Post: 11-04-2013, 07:08 AM
  4. Replies: 3
    Last Post: 06-02-2011, 07:40 AM
  5. VB coding to show current date n time in access form
    By cwwaicw311 in forum Programming
    Replies: 6
    Last Post: 02-10-2010, 09:53 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