Mon code prend toujours la date au-lieu de l'heure

rrupp Messages postés 8 Date d'inscription mercredi 12 mai 2004 Statut Membre Dernière intervention 5 octobre 2005 - 4 oct. 2005 à 03:30
rrupp Messages postés 8 Date d'inscription mercredi 12 mai 2004 Statut Membre Dernière intervention 5 octobre 2005 - 5 oct. 2005 à 02:46
Je dois faire une selection par date ou par heure dans une requête d'access, dans le champ date date pas de problème dans les critères j'ai "Entre #15.08.2005# Et #16.08.2005#" mais par contre dans mon champ Time dans les critères je trouve "Entre #00:00:00# Et #00:00:00#" et pas la valeur que j'ai mis dans ma table, quand je lance le script il prend toujours une date au lieu de l'heure c'est pour la raison que mes critères ont toujours la valeur o, comment faire pour qu'il prenne les heures que j'ai mis dans ma table par exemple"12:30::00 à 18:00:00" .

voici une partie de ma source, merci pour l'aide

Public Function SQLDate(ByVal myDate As Variant) As String
If IsDate(myDate) Then
SQLDate = "#" & Month(myDate) & "/" & Day(myDate) & "/" & Year(myDate) & "#"
End If
End Function


Public Function EnHeure(ByVal myTime As Variant) As String
If IsDate(myTime) Then
EnHeure = "#" & Month(myTime) & "/" & Day(myTime) & "/" & Year(myTime) & "#"
End If
End Function

Public Function DataStart(ByVal myName As String) As Variant
Dim myRS As Recordset
Dim myStart As Variant


Set myRS = CurrentDb.OpenRecordset(myName, dbOpenSnapshot)
If Not myRS.BOF Then
myRS.MoveFirst
End If
If Not myRS.BOF Then
If Not IsNull(myRS.Fields("Date").Value) Then
myStart = myRS.Fields("Date").Value
End If
If Not IsNull(myRS.Fields("Time").Value) Then
If myStart <> Empty Then
myStart = myStart & " " 'Space(2)
End If
myStart = myStart & myRS.Fields("Time").Value
End If
End If
myRS.Close
Set myRS = Nothing
DataStart = myStart
End Function


'------------------------------------------------------------------------

Public Function DataEnd(ByVal myName As String) As Variant
Dim myRS As Recordset
Dim myEnd As Variant


Set myRS = CurrentDb.OpenRecordset(myName, dbOpenSnapshot)
If Not myRS.EOF Then
myRS.MoveLast
End If
If Not myRS.EOF Then
If Not IsNull(myRS.Fields("Date").Value) Then
myEnd = myRS.Fields("Date").Value
End If
If Not IsNull(myRS.Fields("Time").Value) Then
If myEnd <> Empty Then
myEnd = myEnd & " " 'Space(2)
End If
myEnd = myEnd & myRS.Fields("Time").Value
End If
End If
myRS.Close
Set myRS = Nothing
DataEnd = myEnd
End Function

'------------------------------------------------------------------
'open recordset
Set myRS = CurrentDb().OpenRecordset("Selections")
If Not myRS Is Nothing Then


'find record
If Not myRS.BOF Then
myRS.MoveFirst
End If
Do While Not myRS.EOF
If Not IsNull(myRS.Fields("Selection").Value) Then
If myRS.Fields("Selection").Value = myIndex Then
Exit Do
End If
End If
myRS.MoveNext
Loop
If Not myRS.EOF Then


'get date range
myVon = Empty
If IsDate(myRS.Fields("FromDate").Value) Then
myVon = CDate(myRS.Fields("FromDate").Value)
End If
myBis = Empty
If IsDate(myRS.Fields("ToDate").Value) Then
myBis = CDate(myRS.Fields("ToDate").Value)
End If
'compose where
myField = "Date"
If myBis <> Empty Then
If myVon <> Empty Then
If myBis > myVon Then
myDate = myField & " BETWEEN " & SQLDate(myVon) & " AND " & SQLDate(myBis)
Else
If myVon = myBis Then myDate myField & " " & SQLDate(myVon)
Else
'error: end above start
End If
End If
Else
myDate = myField & " <= " & SQLDate(myBis)
End If
Else
If myVon <> Empty Then
myDate = myField & " >= " & SQLDate(myVon)
End If
End If
If myDate <> Empty Then
Debug.Print myDate
End If


'get Time range
myVon = Empty
If IsDate(myRS.Fields("FromTime").Value) Then
myVon = CDate(myRS.Fields("FromTime").Value)
End If
myBis = Empty
If IsDate(myRS.Fields("ToTime").Value) Then
myBis = CDate(myRS.Fields("ToTime").Value)
End If
'compose where
myField = "Time"
If myBis <> Empty Then
If myVon <> Empty Then
If myBis > myVon Then
myTime = myField & " BETWEEN " & EnHeure(myVon) & " AND " & EnHeure(myBis)
Else
If myVon = myBis Then myTime myField & " " & EnHeure(myVon)
Else
'error: end above start
End If
End If
Else
myTime = myField & " <= " & EnHeure(myBis)
End If
Else
If myVon <> Empty Then
myTime = myField & " >= " & EnHeure(myVon)
End If
End If
If myTime <> Empty Then
Debug.Print myTime
End If

Robert

3 réponses

cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
4 oct. 2005 à 06:35
Sans trop regarder ton code, je pense que ca vient de là :



Public Function EnHeure(ByVal myTime As Variant) As String

If IsDate(myTime) Then

EnHeure = "#" & Hour(myTime) & ":" & Minute(myTime) & ":" & Seconde(myTime) & "#"

End If

End Function

_____________________________________________________________________
DarK Sidious

Un API Viewer (pour le VB, VB.NET, C, C# et Delphi) tout en français : www.ProgOtoP.com/popapi/
0
rrupp Messages postés 8 Date d'inscription mercredi 12 mai 2004 Statut Membre Dernière intervention 5 octobre 2005
5 oct. 2005 à 01:28
Salut,
j'avais déjà mis une fois cette solution et là dans ma requête le champ Date et Time sont vites, avec le code EnHeure = "#" & Month(myTime) & "/" & Day(myTime) & "/" & Year(myTime) & "#" si je met une date j'ai "Entre #15.08.2005# Et #16.08.2005#" et avec une heure par ex. dans début 12:00:00 et 16:00:00 dans fin je trouve la valeur "Entre #00:00:00# Et #00:00:00#" car il prend toujours la valeur "Time#12/30/1899# AND #12/30/1899#" au lieu de lire réelement ce qu'il y a dans les cases je pose la question si le problème ne vient pas de IsDate??
(ma source se trouve dans VB d'access) j'utilise le programme pour les rapports des caisses enregistreuse avec une base de données access.
Merci pour ton aide

Robert
0
rrupp Messages postés 8 Date d'inscription mercredi 12 mai 2004 Statut Membre Dernière intervention 5 octobre 2005
5 oct. 2005 à 02:46
Re-Salut,

Je me rapproche de la solution, je supprime la partie du code





Public Function EnHeure(ByVal myTime As Variant) As String


If IsDate(myTime) Then


EnHeure = "#" & Month(myTime) & "/" & Day(myTime) & "/" & Year(myTime) & "#"


End If


End Function









Maintenant il prend la bonne valeur (Time >=12:00:00) AND (Time<=16:30:00)
mais par contre j'ai maintenant l'erreur "3075 erreur de syntaxe opérateur absent dans dans l'expression, dans les divers forum ils indiquent qu'il n'y pas de valeur dans le formulaire, pourtant il voit bien la valeur de départ et fin ?? aurai tu une idée à ce sujet
Salutations
R.R.




Quelques changements dans « get Time range »


'get Time range


myVon = Empty


If Not IsNull(myRS.Fields("FromTime").Value) Then


myVon = CDate(myRS.Fields("FromTime").Value)


End If


myBis = Empty


If Not IsNull(myRS.Fields("ToTime").Value) Then


myBis = CDate(myRS.Fields("ToTime").Value)


End If


'compose where


myField = "Time"


If myBis <> Empty Then


If myVon <> Empty Then


If myBis > myVon Then


myTime = "(" & myField & " >= " & myVon & ")" & " AND " & "('" & myField & " '<= " & myBis & ")"


Else


If myVon = myBis Then


myTime myField & " " & myVon


Else


Beep 'error: end above start


End If


End If


Else


myTime = myField & " <= " & myBis


End If


Else


If myVon <> Empty Then


myTime = myField & " >= " & myVon


End If


End If


If myTime <> Empty Then


Debug.Print myTime


End If

-------------------------------------------------------
Robert
0
Rejoignez-nous