godlike
Goto Top

Access - Problem mit DLookUp bzw. DCount und Datumsvergleich

Hallo,

ich möchte automatisch IDs generieren, ausgehend von einer StartID (Gegeben in der Tabelle "IDs" , erstes DLookUp)
und in Abhängigkeit vom Datum. D.h. das niedrigste Datum soll die niedrigste ID haben, das höchste Datum die höchste ID.

Die Tablle tblVorgänge muss man sich in etwa so vorstellen:

Barcode | Datum | Label (auf Label kommt die ID)
xyz | 01.01.2007 | 0
abc | 02.02.2008 | 0


Die soll nach dem Update so aussehen:

Barcode | Datum | Label (Startwert = 10001 in der ID-Tabelle)
xyz | 01.01.2007 | 10001
abc | 02.02.2008 | 10002


Dafür mache ich folgendes:

UPDATE tblVorgänge SET tblVorgänge.LABEL = 
CLng(DLookUp("ID_START","IDs","ID_Typ='Vorgänge'")) +  
CLng(DCount("Datum","tblVorgänge","[Datum] < #" & Format([tblVorgänge].[Datum], "dd-mm-yy hh:nn:ss") & "#"))  
;

Allerdings ergibt das DCount (und ein DLookup, das bis auf den ersten Parameter (wäre dann "COUNT(Datum)") gleich ist)
immer (Anzahl Datensätze insgesamt). Im oben genannten Beispiel würde dann auf beiden Feldern 10003 stehen (Startwert + Anzahl Datensätze).

Wenn ich im VBA folgendes mache funktioniert das DLookUp komischerweise:

anzahl = DLookup("COUNT(Datum)", "tblVorgänge", "[Datum] < #" & Format("01.01.2007", "dd-mm-yyyy hh:nn:ss") & "#")  
ergibt 0
anzahl = DLookup("COUNT(Datum)", "tblVorgänge", "[Datum] < #" & Format("02.02.2008", "dd-mm-yyyy hh:nn:ss") & "#")  
ergibt 1

Kann mir jemand erklären was ich falsch mache?

Danke im voraus!

Content-Key: 87682

Url: https://administrator.de/contentid/87682

Printed on: April 26, 2024 at 16:04 o'clock

Member: AndreasHoster
AndreasHoster May 15, 2008 at 13:49:55 (UTC)
Goto Top
Nö, weil in meinem Access (Access 2003) funktioniert es mit Deiner Update Formel.
Es gibt natürlich ein Problem, wenn mehrere Einträge das gleiche Datum haben, aber ansonsten funktioniert es wie gewünscht.
Member: Godlike
Godlike May 15, 2008 at 14:30:40 (UTC)
Goto Top
Ich hab das Problem endlich gefunden...
Statt "dd-mm-yy hh:nn:ss" habe ich "yyyy-mm-dd hh:nn:ss" genommen und damit hat es funktioniert.

Vielleicht ist mein Access 2000 da empfindlicher...
Trotzdem danke für den Hinweis, das Access 2003 da anscheinend etwas unempfindlicher ist.