Accueil > > > MODULE ACCESS : REQUETESQL->QUERY->OUERTURE REPORT->EXPORTATION DU REPORT
MODULE ACCESS : REQUETESQL->QUERY->OUERTURE REPORT->EXPORTATION DU REPORT
Information sur la source
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 ...
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
ouverture d'un report access [ par matlepirate ]
HI Comment faut-il procéder pour ouvrir un état access sous VB ?J'arrive à l'imprimer mais pas à l'ouvrir ....Je ne trouve pas d'exemple..Thanks
ouverture d'un report access [ par matlepirate ]
HI Comment faut-il procéder pour ouvrir un état access sous VB ?J'arrive à l'imprimer mais pas à l'ouvrir ....Je ne trouve pas d'exemple..Thanks
access 2000 ouverture et edition de requete en code [ par Gauthier62 ]
Bonjour a tous, voila je vous demande de l'aide concernant mon probleme, je developpe sous access 2000 en vba et je suis ammener dans mon code a ouvri
erreur 2465 lors de l'ouverture d'un report access [ par zolt4n ]
Voila j'ai un programme qui ouvre un etat c'est bidon quand je clic sur un bouton jai ce code la Docmd.openReport "Etat_nom",AcViewPreview sa mar
ouverture d'un report access [ par risque ]
Slt comment ouvrir un report access a partir de VB
résultat d'une requete Access dans un fichier txt [ par lulusky ]
comment lire ligne par ligne le résultat d'une requete access pour pouvoir écrire plusieurs lignes dans un fichier txtlulusky
VB6 et Crystal report 10 [ par DOMBUG ]
Bonjour à tous,Je reprend une application, VB6, Access 2002 utilisant Crystal Report 8.5 afin de la faire évoluer vers une base MS SQL.Dans un permier
Requete parametree sous access [ par eulmaraud ]
Salut à tousun truc tout bête pour certains mais moi, ce soir j'y arrive po et je vais me coucher en ragej'ai, sous access, une requete parametree app
Vue paramétrée Access et VB [ par fairy22 ]
Bonjour, Après de nombreuses recherches sur internet, je n'ai toujours pas de réponse à mon problème...Voici mon souci : J'ai une requete parametrée q
requete access [ par chaudier37 ]
bonjourje travaille dans accessj'ai trois tablesune table sociétéavec une liste de sociétésune table métieravec une liste de métiersune table employéa
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|