Vaida rašė:
> Čia mano procedūra, į kurią kreipiamasi kaskart updatinus kuri nors lauka.
>
> <...>
>
> If Not IsNull(Me.DataNuo) And Not IsNull(Me.DataIki) Then
> Nuo = Me.DataNuo
> Iki = Me.DataIki
Koks yra Nuo, Iki kintamųjų duomenų tipas? Variant? Ir kokio formato yra
įvedama data? Kompiuterio regioniniai nustatymai?
> strfiltras = strfiltras & "[dtmSiuntosData] >= '" & Nuo & "' And
> [dtmSiuntosData] <= '" & Iki & "' And "
> ElseIf Not IsNull(Me.DataNuo) Then
> Nuo = Me.DataNuo
> strfiltras = strfiltras & "[dtmSiuntosData] >= '" & Nuo & "' And "
> ElseIf Not IsNull(Me.DataIki) Then
> Iki = Me.DataIki
> strfiltras = strfiltras & "[dtmSiuntosData] <= '" & Iki & "' And "
> End If
Lyrinė priešistorija, nukrypimas -- *Access'o* užklausose access'o db
datas reikia nurodyti įvelkant jas į ##, pvz.: "[dtmSiuntosData] >= #"
& Nuo & "# ..."
http://articles.techrepublic.com.com/5100-10878_11-6135056.html
When you specify the criteria argument, date literals (date literal: Any
sequence of characters with a valid format that is surrounded by number
signs (#). Valid formats include the date format specified by the locale
settings for your code or the universal date format.) must be in U.S.
format, even if you are not using the U.S. version of the Microsoft
Access database engine. For example, May 10, 1996, is written 10/5/96 in
the United Kingdom and 5/10/96 in the United States. Be sure to enclose
your date literals with the number sign (#) as shown in the following
examples.
Pačios problemos esmė yra ta, kad naudojamas (kintamųjų) datos formatas
yra (ar gali būti) vienoks (jis priklauso nuo kompiuterio regioninių
nustatymų), o duomenų bazėje galbūt kitas
Reikėtų tai suderinti; vienas iš būdų būtų naudoti Format funkciją.
Jei db yra access'e:
If Not IsNull(Me.DataNuo) And Not IsNull(Me.DataIki) Then
Nuo = Format$(Me.DataNuo, "mm\/dd\/yyyy")
Iki = Format$(Me.DataIki, "mm\/dd\/yyyy")
<...>
strfiltras = strfiltras & "[dtmSiuntosData] >= #" & Nuo & "# And
[dtmSiuntosData] <= #" & Iki & "# And "
Tuo atveju, jei db yra SQL serveryje, tai datas reikėtų konvertuoti į
ANSI/ISO) formatą:
If Not IsNull(Me.DataNuo) And Not IsNull(Me.DataIki) Then
Nuo = Format$(Me.DataNuo, "yyyy-mm-dd")
Iki = Format$(Me.DataIki, "yyyy-mm-dd")
<...>
strfiltras = strfiltras & "[dtmSiuntosData] >= '" & Nuo & "' And
[dtmSiuntosData] <= '" & Iki & "' And "
Tingiu tikrinti ar SQL serveriui tinka ANSI formato datos be laiko
dalies (yyy-mm-dd); galbūt reikia pridėti ir pusiaudienio laiką (jei
lygini tik datas):
Nuo = Format$(Me.DataNuo, "yyyy-mm-dd 12:00:00")
Iki = Format$(Me.DataIki, "yyyy-mm-dd 12:00:00")
Na, o ISO 8601 formato data turėtų būti:
Nuo = Format$(Me.DataNuo, "yyyy-mm-dd") & "T12:00:00"
Iki = Format$(Me.DataIki, "yyyy-mm-dd") & "T12:00:00"