Results 1 to 6 of 6
  1. #1
    peshonzi is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    21

    Use data as criteria

    Hello,



    I've created two tables. Both of them contain Date-fields.
    The first table is the GENERAL table, where I store data (NOT TIME!).
    The SECOND table is used only to input Date.

    So, I want to create a query that will filter the data from GENERAL, according to the Date that I've typed in the SECOND table, using a SQL code (something similar to SELECT FROM).

    I want exactly a SQL code, because the situation is more difficult than I describe it. It's just to explain it simplier for understanding.

  2. #2
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209

    Use data as criteria

    Code:
    SELECT General.*
    FROM General, CritTable
    WHERE (((General.CaseDate)=[DateParam]));
    General is the main data table. critTable is having only one field: DateParam and with only one record. Both Tables are placed on the Query Design surface. critTable should have only one record. More than one record will duplcate the output from the data table.

    You can create a Query for the same output differently without placing the critTable on the Design Surface like:

    Code:
    SELECT General.*
    FROM General
    WHERE (((General.CaseDate)=DLookUp("DateParam","critTable")));
    In this method we are using the Dlookup() Functiion to read and bring the date value from the DateParam field of critTable as criteria.

    There is another method you can use for the same result with a Sub-Query in the criteria row like:

    Code:
    SELECT General.*
    FROM General
    WHERE (((General.CaseDate)=(SELECT DateParam FROM critTable;)));
    You can use any of the three methods above.

  3. #3
    peshonzi is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    21
    Well, I've typed those three things, but non of that worked: "The syntax of the subquery in this expression is incorrect". (for all of them)

    If this will help:

    SELECT History.Zaqvitel, History.Belejka_nomer, History.Chas, History.Minyti, History.Obekt, History.Vid_beton, History.Himicheska_dobavka, History.Pompa, History.Shofior, History.Kolichestvo, History.Faktura, History.Vuzel, History.Date, Datata.Datata1
    FROM History, Datata
    ORDER BY History.Zaqvitel, History.Belejka_nomer;


    The main table is - [History]
    The date table is - [Datata]

    The main date field is - [Date]
    The help field is - [Datata1]

  4. #4
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209
    Code:
    SELECT History.Zaqvitel, History.Belejka_nomer, History.Chas, History.Minyti, History.Obekt, History.Vid_beton, History.Himicheska_dobavka, History.Pompa, History.Shofior, History.Kolichestvo, History.Faktura, History.Vuzel, History.Date
    FROM History, Datata
    WHERE (History.Date = Datata.Datata1)
    ORDER BY History.Zaqvitel, History.Belejka_nomer;

  5. #5
    peshonzi is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    21
    Honestly, it doesn't work...

    Maybe I am too stupid for access..

    I will attach you a Sample that I made...

    There is a slight change of names - instead of [Date] - [Data], and maybe something else, that I missed to say... but it is quite a simple table!

    Please, look at it, because I am getting discouraged...

    PLEASE

  6. #6
    peshonzi is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    21
    I found the mistake - I was using a field with the name [date], which is an access special word, so that was the problem... Thanks a lot!

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

Similar Threads

  1. Replies: 18
    Last Post: 04-21-2011, 10:38 AM
  2. Data type mismatch in criteria expression
    By Douglasrac in forum Forms
    Replies: 3
    Last Post: 11-23-2010, 10:46 AM
  3. data type mismatch in criteria expression
    By broecher in forum Access
    Replies: 4
    Last Post: 09-10-2010, 08:29 AM
  4. Data type mismatch in criteria expression
    By shexe in forum Queries
    Replies: 2
    Last Post: 09-01-2010, 12:47 PM
  5. Replies: 6
    Last Post: 09-25-2009, 12:40 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