begin process at 2008 09 05 07:19:03
1 237 085 membres
52 nouveaux aujourd'hui
14 312 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

MODULE ACCESS : REQUETESQL->QUERY->OUERTURE REPORT->EXPORTATION DU REPORT


Information sur la source

Catégorie :Base de Donnees Classé sous : access, requete, ouverture, report, query Niveau : Initié Date de création : 28/02/2001 Vu : 9 929

Note :
6,17 / 10 - par 6 personnes
6,17 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note

Description

bah ...
Tu as une requetes SQL en chaine de caracteres (genre tu la generes dans un formulaire ...)

Tu veux la stocker dans une Query (objet requete d'ACCESS) et ensuite ouvrir un report qui se refaire a la dite query, et exporter ce report


Et bien tu appeles la fonction avec tout les arguments

Source

  • Function EditReportFromQuery(StrSQL As String, Query_name As String, Report_Name As String, Filename As String, Format As String) As Boolean
  • ' Edit the report named R_name after having repalce the query Q_name by the StrSQL
  • ' if a param is NULL then try to ignore it ... or error
  • ' return false if error
  • '* Variable :
  • Dim Q_select As QueryDef ' the querydef that will contains the "select" query (i.e a string)
  • Dim query As String ' the "select" query
  • Dim Q_name As String ' name of the query in this database
  • Dim R_name As String ' name of the report
  • Dim query_def As QueryDef
  • Dim ook As Boolean
  • '*Begin Sub
  • On Error GoTo Erro
  • If IsNull(Report_Name) Then
  • MsgBox "no report name ...?", vbCritical
  • End If
  • If IsNull(Query_name) Then
  • MsgBox "no query ...?", vbCritical
  • EditReportFromQuery = False
  • Exit Function
  • End If
  • R_name = Report_Name
  • Q_name = Query_name
  • If Not IsNull(StrSQL) Then
  • ' create a query with this SQL string
  • For Each query_def In CurrentDb.QueryDefs
  • If query_def.Name = Q_name Then
  • CurrentDb.QueryDefs.Delete (Q_name)
  • Exit For
  • End If
  • Next query_def
  • 'creation
  • Set Q_select = CurrentDb.CreateQueryDef(Q_name, StrSQL)
  • Else
  • 'if this querydef existing ?
  • ook = False
  • For Each query_def In CurrentDb.QueryDefs
  • If query_def.Name = Q_name Then
  • ook = True
  • Exit For
  • End If
  • Next query_def
  • If ook = False Then
  • MsgBox "no query ...?", vbCritical
  • EditReportFromQuery = False
  • Exit Function
  • End If
  • End If
  • 'open the query as a table
  • DoCmd.OpenQuery Q_name, acViewNormal
  • 'open the correponding report
  • DoCmd.OpenReport R_name, acViewPreview
  • 'output to a txt file
  • If Not IsNull(Filename) And Filename <> "NILL" Then
  • Select Case Format
  • Case "HTML"
  • DoCmd.OutputTo acOutputReport, R_name, acFormatHTML, Filename, True
  • Case "RTF"
  • DoCmd.OutputTo acOutputReport, R_name, acFormatRTF, Filename, True
  • Case "TXT"
  • DoCmd.OutputTo acOutputReport, R_name, acFormatTXT, Filename, True
  • Case "XLS"
  • DoCmd.OutputTo acOutputReport, R_name, acFormatXLS, Filename, True
  • End Select
  • End If
  • EditReportFromQuery = True
  • Exit Function
  • Erro:
  • If Err.Number <> 2501 Then
  • EditReportFromQuery = False
  • MsgBox "EditReportFromQuery : " & Err.Description, vbCritical, Err.Number
  • DoCmd.Close
  • End If
  • End Function
Function EditReportFromQuery(StrSQL As String, Query_name As String, Report_Name As String, Filename As String, Format As String) As Boolean
' Edit the report named R_name after having repalce the query Q_name by the StrSQL
' if a param is NULL then try to ignore it ... or error
' return false if error

'* Variable :
    Dim Q_select As QueryDef ' the querydef that will contains the "select" query (i.e a string)
    Dim query As String ' the "select" query
    Dim Q_name As String ' name of the query in this database
    Dim R_name As String ' name of the report
    Dim query_def As QueryDef
    Dim ook As Boolean

'*Begin Sub
    
On Error GoTo Erro
     If IsNull(Report_Name) Then
        MsgBox "no report name ...?", vbCritical
     End If
     If IsNull(Query_name) Then
        MsgBox "no query ...?", vbCritical
        EditReportFromQuery = False
        Exit Function
     End If
    R_name = Report_Name
    Q_name = Query_name
    If Not IsNull(StrSQL) Then
        ' create a query with this SQL string
        For Each query_def In CurrentDb.QueryDefs
            If query_def.Name = Q_name Then
                CurrentDb.QueryDefs.Delete (Q_name)
                Exit For
            End If
        Next query_def
        'creation
        Set Q_select = CurrentDb.CreateQueryDef(Q_name, StrSQL)
    Else
        'if this querydef existing ?
        ook = False
        For Each query_def In CurrentDb.QueryDefs
            If query_def.Name = Q_name Then
                ook = True
                Exit For
            End If
        Next query_def
        If ook = False Then
            MsgBox "no query ...?", vbCritical
            EditReportFromQuery = False
            Exit Function
        End If
    End If
    
    'open the query as a table
    DoCmd.OpenQuery Q_name, acViewNormal
    'open the correponding report
    DoCmd.OpenReport R_name, acViewPreview
    'output to a txt file
    If Not IsNull(Filename) And Filename <> "NILL" Then
        Select Case Format
                Case "HTML"
                    DoCmd.OutputTo acOutputReport, R_name, acFormatHTML, Filename, True
                Case "RTF"
                    DoCmd.OutputTo acOutputReport, R_name, acFormatRTF, Filename, True
                Case "TXT"
                    DoCmd.OutputTo acOutputReport, R_name, acFormatTXT, Filename, True
                Case "XLS"
                    DoCmd.OutputTo acOutputReport, R_name, acFormatXLS, Filename, True
                End Select
    End If
    
    EditReportFromQuery = True
    Exit Function

Erro:
        If Err.Number <> 2501 Then
            EditReportFromQuery = False
            MsgBox "EditReportFromQuery : " & Err.Description, vbCritical, Err.Number
            DoCmd.Close
        End If
End Function
 

Conclusion

c est hyper long , mais y a des appels de fonctions utiles ...
  • signaler à un administrateur
    Commentaire de Lolux le 04/02/2002 09:43:49

    T'as trouvé ça où ??

    T'es bilingue ?

  • signaler à un administrateur
    Commentaire de batmoun le 17/09/2003 10:26:38

    Pfff ... j'ai codé ca en 2001 !
    j suis pas bilingue d'ailleur y a plein de fautes dans les commentaires.

    je travaillais à l'étranger, donc en anglais (tu sais , if , ca veut dire Si en francais ... le code, c'est fait pour être en anglais :p )

Ajouter un commentaire

Pub



Appels d'offres

Recherche developpeur ...
Budget : 700€
SITE MARCHAND LOCATION...
Budget : 3 000€
SITE MARCHAND POUR HOTEL
Budget : 4 000€

CalendriCode

Septembre 2008
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
2930     

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

Logiciels à télécharger sur le même thème :

Boutique

Boutique de goodies CodeS-SourceS