Trier une requete et usercontrol

Résolu
ecranbleu27 Messages postés 190 Date d'inscription vendredi 4 juin 2004 Statut Membre Dernière intervention 29 avril 2009 - 25 mai 2007 à 08:04
ecranbleu27 Messages postés 190 Date d'inscription vendredi 4 juin 2004 Statut Membre Dernière intervention 29 avril 2009 - 25 mai 2007 à 10:40
bjr
en VB6+ ACCESS
je gére une BD access, avec un usercontrol
(c'est en fait un menu qui me permet de naviguer dans les enregistrements avec ajout,modif,supp tec...)
sur mon premier form, il y a donc les champs de saisies , le usercontrol et un datagrid qui me fait une récap de tous les enregistrements.
c'est tout bete , mais je voudrais les trier dans l'ordre croissant des dates (par exemple)
je sais bien sur écrire la requete SQL, mais vu que ca dépend d'un usercontrol (la gestion des enregistrements) nulle part j'arrive a placer ma requete pour que ca marche.....

si quelqu'un a une idée.....
merci d'avance.

6 réponses

cs_Nicko11 Messages postés 1141 Date d'inscription mercredi 7 mars 2007 Statut Membre Dernière intervention 19 septembre 2007 3
25 mai 2007 à 10:07
Moi, perso, il y a un truc que je ne comprends pas (orange ok, violet pas ok)

If m_tag = "2" Then  ( ce n'est pas ce tag qui est en cause mais tag=1)   
    m_sql = "select * from table where num like '" & Frm1.TxtSort(0) & "' ORDER BY [date]"
    adoRecordset.Open m_sql, adoConnection, , , adCmdText
    With adoRecordset
       ltotalrecords = .RecordCount 
    End With
Else
    m_sql = "select * from sortie order BY [date] desc"
    adoRecordset.Open m_recordSource, adoConnection, , , adCmdTable
End If
3
cs_Exploreur Messages postés 4821 Date d'inscription lundi 11 novembre 2002 Statut Membre Dernière intervention 15 novembre 2016 15
25 mai 2007 à 08:59
Salut,

Regarde du côté(pour la requête SQL), ODER BY...

A+
Exploreur

 Linux a un noyau, Windows un pépin

 
0
cs_Nicko11 Messages postés 1141 Date d'inscription mercredi 7 mars 2007 Statut Membre Dernière intervention 19 septembre 2007 3
25 mai 2007 à 09:06
Oui en effet, comme le dis Exploreur, c'est une requete du genre :

"Select * From ta_table ORDER BY ton_champ ASC"       (ou DSC)

Si tu n'y arrives pas, montre nous ta requete.
0
ecranbleu27 Messages postés 190 Date d'inscription vendredi 4 juin 2004 Statut Membre Dernière intervention 29 avril 2009 1
25 mai 2007 à 09:28
bjr
bien sur que c'est avec "order by"
mais c'est le usercontrol qui ouvre la base sous la forme :
usercontrol.ctl
usercontrol.ctx

le code: (je n'ai pas mis bien sûr tout le code, juste ce qui je pense est important ...)




Option Explicit





'-- Default Property Values

Const m_def_connectionString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=mabase.mdb"
Const m_def_recordSource = ""
Const m_def_sql = "select * from matable order by [date] DESC" (j'ai rajouté ici la requete SQL, mais ca ne marche pas....)
etc.....
'Declare our object variables for the ADO connection
'and the recordset used in the control
Public adoConnection As ADODB.Connection
Public adoRecordset As ADODB.Recordset
Public adocombo As ADODB.Recordset

Private Sub UserControl_GetDataMember(DataMember As String, Data As Object)
Dim iReturn As Integer
'-Reasonability test --
   On Error GoTo UserControl_GetDataMember_Error
   
  
If (adoRecordset Is Nothing) Or (adoConnection Is Nothing) Then
  If Trim$(m_connectionstring) = "" Then
    iReturn = MsgBox("There is no connection string!", _
    vbCritical, Ambient.DisplayName)
    Exit Sub
  End If


  If Trim$(m_recordSource) = "" Then
    iReturn = MsgBox("There is no recordsource!", vbCritical, _
                                  Ambient.DisplayName)
    Exit Sub
  End If
 
   
Set adoConnection = New ADODB.Connection
adoConnection.Open m_connectionstring
 
Set adoRecordset = New ADODB.Recordset




adoRecordset.CursorLocation = adUseClient
adoRecordset.CursorType = adOpenDynamic
adoRecordset.LockType = adLockOptimistic


 
If m_tag = "2" Then  ( ce n'est pas ce tag qui est en cause mais tag=1)
   
   m_sql = "select * from table where num like '" & Frm1.TxtSort(0) & "' ORDER BY [date]"
    adoRecordset.Open m_sql, adoConnection, , , adCmdText
    With adoRecordset
    ltotalrecords = .RecordCount
 
    End With
    Else
    m_sql = "select * from sortie order BY [date] desc"
    adoRecordset.Open m_recordSource, adoConnection, , , adCmdTable
    End If
ltotalrecords = adoRecordset.RecordCount


Set m_form = UserControl.Parent


UserControl.BackColor = m_form.BackColor
                    UserControl.ReyFrame1.BackColor = m_form.BackColor
                    UserControl.ReyFrame2.BackColor = m_form.BackColor
etc.....

Private Sub UserControl_Initialize()
   editStatus = nowStatic
End Sub




Private Sub UserControl_InitProperties()

    m_tag = m_def_Tag
    m_sql = m_def_sql
   m_recordSource = m_def_recordSource
   m_connectionstring = m_def_connectionString
   
End Sub




Private Sub UserControl_ReadProperties(PropBag As PropertyBag)


m_recordSource = PropBag.ReadProperty("RecordSource", _
m_def_recordSource)


m_connectionstring = PropBag.ReadProperty _
("ConnectionString", m_def_connectionString)


m_tag = PropBag.ReadProperty("Tag", m_def_Tag)


m_sql = PropBag.ReadProperty("sql", m_def_sql)
   
End Sub




Private Sub UserControl_WriteProperties(PropBag As PropertyBag)



Call PropBag.WriteProperty("sql", _
m_sql, m_def_sql)
Call PropBag.WriteProperty("RecordSource", _
m_recordSource, m_def_recordSource)
Call PropBag.WriteProperty("ConnectionString", _
m_connectionstring, m_def_connectionString)
Call PropBag.WriteProperty("Tag", m_tag, m_def_Tag)
End Sub






Private Sub UserControl_Resize()

   Width = UserControl.ScaleX(m_def_Width, vbPixels, vbTwips)
   Height = UserControl.ScaleX(m_def_Height, vbPixels, vbTwips)
  


End Sub




Private Sub UserControl_Terminate()

On Error Resume Next
If Not adoRecordset Is Nothing Then
  Set adoRecordset = Nothing
End If


If Not adoConnection Is Nothing Then
  Set adoConnection = Nothing
End If


Err.Clear


End Sub


 




Public Property Get RecordSource() As String

Attribute RecordSource.VB_ProcData.VB_Invoke_Property = "PropertyPage1"
   RecordSource = m_recordSource
End Property




Public Property Let RecordSource(ByVal New_RecordSource As String)

    m_recordSource = New_RecordSource
    PropertyChanged "RecordSource"
End Property




Public Property Get ConnectionString() As String

Attribute ConnectionString.VB_ProcData.VB_Invoke_Property = "PropertyPage1"
   ConnectionString = m_connectionstring
  
End Property




Public Property Let ConnectionString(ByVal New_ConnectionString As String)

   m_connectionstring = New_ConnectionString
   PropertyChanged "ConnectionString"
  
End Property






Public Property Get Tag() As String

Attribute Tag.VB_ProcData.VB_Invoke_Property = "PropertyPage1"
Tag = m_tag
End Property




Public Property Let Tag(ByVal vNewValue As String)

m_tag = vNewValue
PropertyChanged "Tag"
End Property

merci
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
ecranbleu27 Messages postés 190 Date d'inscription vendredi 4 juin 2004 Statut Membre Dernière intervention 29 avril 2009 1
25 mai 2007 à 10:27
ah ben...
mais c'est peut-etre ca mon pb, effectivement ce ne devrait pas etre m_recordsource mais m_sql si je veux que la requete se fasse....
je vais tester......
0
ecranbleu27 Messages postés 190 Date d'inscription vendredi 4 juin 2004 Statut Membre Dernière intervention 29 avril 2009 1
25 mai 2007 à 10:40
YES!!!!!
merci encore NIKKO
c'était ca....
Else
    m_sql = "select * from sortie order BY [date] desc"
    adoRecordset.Open m_sql, adoConnection, , , adCmdText
End If

ca maaaaaaaarche....
au plaisir
0
Rejoignez-nous