Avatar billede kimsand Nybegynder
07. januar 2015 - 09:01 Der er 12 kommentarer og
1 løsning

Hjælp til dato og tid i access og vba

Jeg er ved at gå til i frustration over hvordan access virker i forhold til datoer og tid.

Jeg håndterer jævnligt dato og tid i access frontends, VBA og access sql, men hver gang skal jeg hele møllen igennem, med 1.8. som ses som 8.1.

Jeg prøver at løse problemet hver gang, men det tager SÅ LANG TID, og selvom jeg prøver at lave ens løsninger, så virker løsningerne ikke ens på hver situation.

Der må simpelthen være noget grundlæggende jeg ikke forstår.

Derudover er klslæt også begyndt at volde problemer nu.

Jeg har mandag fra - til, tirsdag fra - til etc etc til fredag. Det er tekstfelter som har en inputmaske der ser sådan her ud 00:00;0;_.

Værdien af disse felter bliver lagt over i nogle dato variable manfra, mantil osv. sv.


Disse felter bliver ført ind i en tabel med sql sætningen.

vaerdier = IDplads & ", #" & Forms!FM_opret_ny_modeaftale!fradato & "#, #" & Forms!FM_opret_ny_modeaftale!tildato & "#, #" & manfra & "#, #" & mantil & "#, #" & tirfra & "#, #" & tirtil & "#, #" & onsfra & "#, #" & onstil & "#, #" & torfra & "#, #" & tortil & "#, #" & frefra & "#, #" & fretil & "#, -1"

DoCmd.RunSQL ("insert into DT_modeaftale (IDplads, fradato, tildato, manfra, mantil, tirfra, tirtil, onsfra, onstil, torfra, tortil, frefra, fretil, aktiv) Values (" & vaerdier & ")")


Alle felter bliver behandlet ens, MEN onstil bliver ALTID registreret i backenden som 12:00, selvom jeg kan udlæse dette

Watch :  : vaerdier : "17, #08-01-2015#, #01-07-2015#, #00:00:00#, #00:00:00#, #00:00:00#, #00:00:00#, #10:00:00#, #13:00:00#, #00:00:00#, #00:00:00#, #00:00:00#, #00:00:00#, -1                   

hvor 10:00:00 og 13:00:00 er onsfra og onstil, LIGE INDEN jeg laver DoCmd.RunSQL sætningen.

Er der nogen der kan hjælpe mig med det ?
Avatar billede terry Ekspert
07. januar 2015 - 09:33 #1
I would suggest insert the date in YYYY-MM-DD format

Not easy to see what the problem is without know what all those date time values (in watch) mean. So if its possible to see the dB it may help.
Avatar billede terry Ekspert
07. januar 2015 - 09:37 #2
Looking at the Watch string, these two dates could be
01 august 2015 and 7 January 2015. Both formatted mm-dd-yyyy which is US format.

Is that what you expect?

#08-01-2015#, #01-07-2015#,
Avatar billede kimsand Nybegynder
07. januar 2015 - 10:04 #3
yes the first is 8th of january the second is 1 of july.

The strange thing is its like i cant use the same solution in each case. It seems random if it works or not...

Ive even experienced to work for 2 days on a problem, only to end where i started, but now it worked....
Avatar billede terry Ekspert
07. januar 2015 - 10:28 #4
yes the first is 8th of january the second is 1 of july.

So your dates are formatted incorrectly!
They should either be MM-DD-YYYY or YYYY-MM-DD
Avatar billede terry Ekspert
07. januar 2015 - 10:28 #5
Ive even experienced to work for 2 days on a problem, only to end where i started, but now it worked....


??
Avatar billede kimsand Nybegynder
07. januar 2015 - 13:54 #6
The variable has the correct value until it is written to backend with

sSql = "insert into DT_borgervaerkstedskalender (IDborger, IDplads, dato, aftaltmodtfra, aftaltmodttil) values (" & IDborger & ", " & IDplads & ", #" & Format(xdato, "mm-dd-yyyy", vbMonday, vbFirstFourDays) & "#,#" & modtfra & "#,#" & modttil & "#)"

docmd.runsql (sSql)

then it is written as 15:00.

i can readout the sSql string, and the value is correct, in the next line i do runsql, and it is written with the same value 15:00 every time.
Avatar billede terry Ekspert
07. januar 2015 - 14:06 #7
is it at all possible to see the dB, or at least an example so I can see the problem?

Looking at
Watch :  : vaerdier : "17, #08-01-2015#, #01-07-2015#, #00:00:00#, #00:00:00#, #00:00:00#, #00:00:00#, #10:00:00#, #13:00:00#, #00:00:00#, #00:00:00#, #00:00:00#, #00:00:00#, -1 

If you say that #08-01-2015#, #01-07-2015# are  8th of january the second is 1 of july then I am sure this will not work.

You should insert dates in US format MM.DD-YYYY or yyyy-mm-dd
Avatar billede kimsand Nybegynder
07. januar 2015 - 14:16 #8
i would send it to you if i could, but there are a LOT of data, that should be anonymized, and it would take a lot of time to be sure to do it properly.

But thanks for trying to help me :).

Have you ever experienced a value change when written to DB with docmd.runsql. It changes to the same value every time, no matter what i write in the textbox.

it changes 9:00 to 15:00, it change 13:00 to 15:00

I can see the value up until it is written to DB, when i look in the back end the second it is written it says 15:00. The weirdest thing.
Avatar billede kimsand Nybegynder
07. januar 2015 - 14:24 #9
arrrgh the query had 2 tables and both had the field onstil, and i choose the wrong table :) THANK GOD it was me..

Well if you have some golden basic truth concerning dates in general that would be great...

1 is always write in US style to the DB, are there anymore ?
Avatar billede terry Ekspert
07. januar 2015 - 14:45 #10
What you see in a string isn't necessarily the same as what end
up in the table.

You can find a lot about dates and SQL on the web, but I ALWAYS insert YYYY-MM-DD HH:MM:SS format.

What you see on forms/reports and tables (viewing data) is formatted dependant on your PC's regional settings. The way it is formatted IN the table is always the same no matter which regional (country) settings you use.

So as long as you insert correctly it will always be displayed no matter what regional settings you use.
Avatar billede kimsand Nybegynder
07. januar 2015 - 15:26 #11
you mean mm-dd-yyyy right ?

So if i insert in that format, i can always rely on a proper date registration ?
Avatar billede terry Ekspert
07. januar 2015 - 15:34 #12
you mean mm-dd-yyyy right ?

This is the US and normally accepted format to insert but the format I use yyyy-mm-dd is also acceptable
Avatar billede kimsand Nybegynder
08. januar 2015 - 12:34 #13
ahh okie.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester