I have a query in Access named ' Laufzettel ' and it looks in this way. The dates are in dd.mm.yyyy format
Antragsnummer Eingang esigniert Ausgang Anlage Policierung
111 2.10.2016 2.10.2016 3.10.2016 3.10.2016
222 3.10.2016 3.10.2016 3.10.2016 4.10.2016
333 5.10.2016 6.10.2016 7.10.2016 7.10.2016
I am creating a form named ' overview ' with two Textboxes named StartDate and EndDate and search button. What I need is When I click the search button by giving in two dates it should retrieve me the related records from the above query with all the fields in form of a report.
The StartDate and EndDate are related to the Eingang field of the query. SO when I enter 2.10.2016 as StartDate and 5.10.2016 as EndDate it must produce the above query. To achieve this I have started to create a query using the form fields which in turn can produce me the required report when I click the search button. So I am trying with the code
SELECT Laufzettel.ANTRAGSNUMMER, Laufzettel.Eingang, Laufzettel.esigniert, Laufzettel.Ausgang, Laufzettel.Anlage, Laufzettel.Policierung
FROM Laufzettel
WHERE Lauzettel.Eingang BETWEEN [Forms]![overview]![StartDate] and [Forms]![overview]![EndDate];
For which I get an error Access cannot recognise [Forms]![overview]![StartDate] and [Forms]![overview]![EndDate] as a valid field name or expression
How can I achieve the above? Can someone help me?
EDIT : Here is my working Query now. Although It doesn't give me the records from EndDate values.
PARAMETERS [Forms]![overview]![start] DateTime, [Forms]![overview]![end] DateTime;
SELECT Laufzettel.ANTRAGSNUMMER, Laufzettel.AEingangDatenstromZWorkflow, Laufzettel.BEingangesigniertDokumentZWorkflow, Laufzettel.CAusgangDatenstromZWorkflow, Laufzettel.DAnlageSchwebeVSL, Laufzettel.EPolicierungVSL
FROM Laufzettel
WHERE (((Laufzettel.AEingangDatenstromZWorkflow) Between [Forms]! [overview]![start] And [Forms]![overview]![end]));
Can someone tell me where am I going Wrong?
If build in code (VBA), try with:
SQL = "SELECT Laufzettel.ANTRAGSNUMMER, Laufzettel.Eingang, Laufzettel.esigniert, Laufzettel.Ausgang, Laufzettel.Anlage, Laufzettel.Policierung " & _
"FROM Laufzettel " & _
"WHERE Lauzettel.Eingang BETWEEN #" & Format([Forms]![overview]![StartDate], "yyyy\/mm\/dd") & "# AND #" & Format([Forms]![overview]![EndDate], "yyyy\/mm\/dd") & "#"
If the "date" field really is text, apply DateValue :
SQL = "SELECT Laufzettel.ANTRAGSNUMMER, Laufzettel.Eingang, Laufzettel.esigniert, Laufzettel.Ausgang, Laufzettel.Anlage, Laufzettel.Policierung " & _
"FROM Laufzettel " & _
"WHERE DateValue(Lauzettel.Eingang) BETWEEN #" & Format([Forms]![overview]![StartDate], "yyyy\/mm\/dd") & "# AND #" & Format([Forms]![overview]![EndDate], "yyyy\/mm\/dd") & "#"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.