1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| Option Compare Database
Global ReqSQL As String
Sub cleartable()
Dim delSQL As String
'effacement de la table comparaison par creation de requete
DoCmd.SetWarnings False
delSQL = "DELETE tblcomparaison.*"
delSQL = delSQL & "FROM tblcomparaison;"
DoCmd.RunSQL delSQL
End Sub
Sub construct()
Dim I As Integer, nb As Integer
Dim InsertSQL As String, comparSQL As String
Dim reponse As String
reponse = MsgBox("Rajouter des genoypes pour comparaison?", vbExclamation + vbOKCancel, "rapport")
If reponse = vbCancel Then
'si cancel annuler lexecution de la sub
Exit Sub
Else
'sinon lancer la suite
'effacement de la table comparaison
Call cleartable
'reprise de la reqSQL dans 2 nouvelle variable pour travaux
comparSQL = ReqSQL
InsertSQL = ReqSQL
Debug.Print "etape 2 : " & InsertSQL
' la on recupère la sequence a partir de la gauche jusqu'à FROM non inclus
InsertSQL = Trim(Left(InsertSQL, InStr(InsertSQL, "FROM ") - 1))
Debug.Print "etape 3 : " & InsertSQL
' toutsql est donc egale a "SELECT sqlselect "
' on récupère donc a partir de la droite le sqlselect
' taille global moins toute la partie avec le SELECT et moins le Select lui même
InsertSQL = Right(InsertSQL, Len(InsertSQL) - InStr(InsertSQL, "SELECT ") - Len("SELECT ") + 1)
'affichage dans la fenetre de sélection de la sequence toutsql qui est egale a "sqlselect "
Debug.Print "etape 4 : " & InsertSQL
'if InseI
InsertSQL = Replace(InsertSQL, "Tblsemoule.GENOTYPE", "Tblsemoule_GENOTYPE", 1)
Debug.Print "resultat chamgement : " & InsertSQL
'InsertSQL = "INSERT INTO " & InsertSQL
ReqSQL = "INSERT INTO tblcomparaison (" & InsertSQL & ") " & ReqSQL
Debug.Print "etape 5 : " & ReqSQL
DoCmd.SetWarnings False
DoCmd.RunSQL ReqSQL
DoCmd.Close acform, "frmresults"
DoCmd.Close acform, "frmrecherche"
nb = InputBox("combien de génotype souhaitez vous comparer?", "COMPARAISON")
For I = 1 To nb
MsgBox "entrez du gentoype n°" & I, vbOKOnly
DoCmd.OpenForm "frmcomparaison", WindowMode:=acDialog
'ici code reqsql recuperer plus haut dans module insert into...
'on recup tout le code jusqu'au where apres le where est effacé
ReqSQL = Left(ReqSQL, InStr(ReqSQL, "WHERE ") + 5)
Debug.Print ReqSQL
' ICI MA PROCEDURE IF ....
'SI CLICK SUR BOUTON btnrech alors reconstruit mon code sql pour la clause where
Dim sqlwhere As String
'Reconstruction du where pour filtrages des données
sqlwhere = "(((ReqTOUT.SAMPLE_NUMBER)<>'0')"
'verification du remplissage des box a cases cocher
If Form_Frmcomparaison.Chk_genotype.Value = True And (IsNull(Form_Frmcomparaison.boxgenotype)) Then
MsgBox "Attention! Le champs GENOTYPE est vide, selectionner un Génotype ou décocher la case", vbExclamation + vbOKOnly
Exit Sub
End If
If Form_Frmcomparaison.Chk_annee.Value = True And (IsNull(Form_Frmcomparaison.boxANNEE)) Then
MsgBox "Attention! Le champs ANNEE est vide, selectionner une Année ou décocher la case", vbExclamation + vbOKOnly
Exit Sub
End If
If Form_Frmcomparaison.chk_LIEU.Value = True And (IsNull(Form_Frmcomparaison.boxLIEU)) Then
MsgBox "Attention! Le champs LIEU est vide, selectionner un Lieu ou décocher la case", vbExclamation + vbOKOnly
Exit Sub
End If
If Form_Frmcomparaison.Chk_Trial.Value = True And (IsNull(Form_Frmcomparaison.boxTRIAL)) Then
MsgBox "Attention! Le champs TRIAL est vide, selectionner un Trial ou décocher la case", vbExclamation + vbOKOnly
Exit Sub
End If
If Form_Frmcomparaison.ChkSample.Value = True And (IsNull(Form_Frmcomparaison.boxSAMPLE)) Then
MsgBox "Attention! Le champs SAMPLE_NUMBER est vide, selectionner un Sample_Number ou décocher la case", vbExclamation + vbOKOnly
Exit Sub
End If
If Form_Frmcomparaison.ChkSample.Value = True Then
Dim samp As String
'capture de la valeur de sample
samp = Form_Frmcomparaison.boxSAMPLE.Value
sqlwhere = sqlwhere & " AND ((ReqTOUT.SAMPLE_NUMBER)=""" & samp & """)"
End If
If Form_Frmcomparaison.Chk_genotype.Value = True Then
Dim gen As String
'capture de la valeur pour creer un SQL definitif a sauvegarder si besoin cf plus loin code
gen = Form_Frmcomparaison.boxgenotype.Value
sqlwhere = sqlwhere & " AND ((ReqTOUT.Tblsemoule.GENOTYPE)=""" & gen & """)"
End If
If Form_Frmcomparaison.Chk_annee.Value = True Then
Dim annee As String
annee = Form_Frmcomparaison.boxANNEE.Value
sqlwhere = sqlwhere & " AND ((ReqTOUT.ANNEE)=""" & annee & """)"
End If
If Form_Frmcomparaison.chk_LIEU.Value = True Then
Dim loc As String
loc = Form_Frmcomparaison.boxLIEU.Value
sqlwhere = sqlwhere & " AND ((ReqTOUT.LIEU)=""" & loc & """)"
End If
If Form_Frmcomparaison.Chk_Trial.Value = True Then
Dim trial As String
trial = Form_Frmcomparaison.boxTRIAL.Value
sqlwhere = sqlwhere & " AND ((ReqTOUT.TRIAL)=""" & trial & """)"
End If
ReqSQL = ReqSQL & sqlwhere & ");"
'executer le code sql pour rajouter les nouvelles données dans la table
DoCmd.SetWarnings False
DoCmd.RunSQL ReqSQL
Docmd.setwarnings true
'fermeture du formulaire et passe a la boucle suivante jusqu'a nb
DoCmd.Close acform, "frmcomparaison"
Next I
End If
End Sub |
Partager