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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
| Option Compare Database
Option Explicit
Function OuvreFormulaires(strNomForm As String) As Integer
' Cette fonction est utilisée par l'événement Click des boutons de
' commande qui ouvrent les formulaires dans le menu général. Utiliser une
' fonction est plus efficace que de répéter le même code dans plusieurs
' procédures événementielles.
On Error GoTo Err_OuvreFormulaires
' Ouvre le formulaire spécifié.
DoCmd.OpenForm strNomForm
Quitte_OuvreFormulaires:
Exit Function
Err_OuvreFormulaires:
MsgBox Err.Description
Resume Quitte_OuvreFormulaires
End Function
Private Sub AfficheFenêtreBaseDeDonnées_Click()
' Ce code est créé en partie par l'Assistant Bouton de commande.
On Error GoTo Err_AfficheFenêtreBaseDeDonnées_Click
Dim strNomDoc As String
strNomDoc = "Catégories"
' Ferme le formulaire Menu général.
DoCmd.Close
' Donne le focus à la fenêtre Base de données; sélectionne la table
' Catégories (premier formulaire dans la liste).
DoCmd.SelectObject acTable, strNomDoc, True
Quitte_AfficheFenêtreBaseDeDonnées_Click:
Exit Sub
Err_AfficheFenêtreBaseDeDonnées_Click:
MsgBox Err.Description
Resume Quitte_AfficheFenêtreBaseDeDonnées_Click
End Sub
Private Sub cmdConfig_Click()
On Error Resume Next
Me.Tag = ""
DoCmd.OpenForm "frmPwd", , , , , acDialog
If Me.Tag = "" Then Exit Sub 'no password
DoCmd.OpenForm "frmConfig", , , , , acDialog
End Sub
Private Sub cmdHTML_Click()
'Export HTML
Dim htmlPath As String 'path to generated html files
Dim ret&
Dim db As Database
Dim rst As Recordset
Dim fld As Field
On Error Resume Next
Me.Tag = ""
DoCmd.OpenForm "frmPwd", , , , , acDialog
If Me.Tag = "" Then Exit Sub 'no password
Set db = CurrentDb
Set rst = db.OpenRecordset("tblConfig")
Set fld = rst.Fields(0)
htmlPath = fld.Value
Set fld = Nothing
Set rst = Nothing
Set db = Nothing
ret = MsgBox("Vous allez exporter les informations de la base de donnée, êtes-vous sûr ?", vbYesNo, "Exportation HTML")
If ret = vbYes Then
If Trim$(htmlPath) = "" Then
MsgBox "Exportation décommandée! Le chemin d'exportation non defini !"
Exit Sub
Else
If Right(htmlPath, 1) <> "\" Then htmlPath = htmlPath & "\"
FillTemplate htmlPath
End If
End If
End Sub
Private Sub cmdRecherche_Click()
On Error GoTo Err_recherche_Click
Dim stSQL As String, txtR As String, txtC As String
Dim stDocName As String
Dim db As Database
Dim rst As Recordset
Dim fld As Field
stSQL = ""
txtRecherche.SetFocus
txtR = txtRecherche.Text
cboChamp.SetFocus
txtC = cboChamp.Text
Set db = CurrentDb
Set rst = db.OpenRecordset("Table1")
Set fld = rst.Fields(txtC)
If fld.Type = dbText Or fld.Type = dbMemo Or fld.Type = dbChar Then
txtR = "'" & txtR & "*'"
Else
txtR = "'" & txtR & "'"
End If
Set fld = Nothing
Set rst = Nothing
Set db = Nothing
stSQL = stSQL & "`" & txtC & "` Like " & txtR
stDocName = "Formulaire_Essuyage"
DoCmd.OpenForm stDocName, , , stSQL
Exit_recherche_Click:
Exit Sub
Err_recherche_Click:
MsgBox Err.Description
Resume Exit_recherche_Click
End Sub
Private Sub QuitterMicrosoftAccess_Click()
' Ce code est créé par l'Assistant Bouton de commande.
On Error GoTo Err_QuitterMicrosoftAccess_Click
' Quitte Microsoft Access.
DoCmd.Quit
Quitte_QuitterMicrosoftAccess_Click:
Exit Sub
Err_QuitterMicrosoftAccess_Click:
MsgBox Err.Description
Resume Quitte_QuitterMicrosoftAccess_Click
End Sub
Private Sub Commande20_Click()
On Error GoTo Err_Commande20_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Fiche"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Commande20_Click:
Exit Sub
Err_Commande20_Click:
MsgBox Err.Description
Resume Exit_Commande20_Click
End Sub
Private Sub FillTemplate(ByVal fhtml$)
Dim tmp$, repl$, template$, templorig$, result$
Dim perc As Single, cnt As Long, i As Long
Dim db As Database
Dim rst As Recordset
Dim fld As Field
Dim fileName$
On Error Resume Next
Open "C:\Template.html" For Input As #1
template = Input(LOF(1), #1)
Close #1
templorig = template
QuitterMicrosoftAccess.SetFocus
cmdHTML.Visible = False
'cmdHTML.Enabled = False
Set db = CurrentDb
Set rst = db.OpenRecordset("Table Fiche Produit")
lblPerc.Caption = "0.0 %"
cnt = rst.RecordCount
If cnt <= 0 Then
MsgBox "Table Fiche Produit is empty !"
Set fld = Nothing
Set rst = Nothing
Set db = Nothing
cmdHTML.Visible = True
'cmdHTML.Enabled = True
Exit Sub
Else
'erase all files
Kill fhtml & "*.html"
rst.MoveLast
rst.MoveFirst
i = 0
Do While Not rst.EOF
tmp = ""
If Trim(rst.Fields("N/REF").Value) = "" Or IsNull(rst.Fields("N/REF").Value) Then 'if we don't have a N/REF
fileName = "NoNREF.html"
Else
fileName = rst.Fields("N/REF").Value & ".html"
End If
'tmp = tmp & "<table cellspacing='1' cellpadding='2' bgcolor='#808080' border='0'>"
template = templorig
For Each fld In rst.Fields
'tmp = tmp & "<tr><td bgcolor='F0F0F0'>" & fld.Name & "</td><td bgcolor='FFFFFF'>" & fld.Value & "</td></tr>"
If IsNull(fld.Value) Then
repl = " "
Else
repl = fld.Value
End If
tmp = Replace(template, "$" & fld.Name, repl, , , vbTextCompare)
If tmp <> "" Then template = tmp
Next fld
'tmp = tmp & "</table><BR>"
'here we save the html file
If tmp <> "" Then
Open fhtml & fileName For Append As #1
Print #1, tmp
Close #1
End If
'update progress bar
perc = i / cnt
prg.Width = perc * framePrg.Width
lblPerc.Caption = Format$(perc * 100, "0.0") & " %"
i = i + 1
DoEvents
'uncomment next line just for testing phase!!!
'Exit Do
rst.MoveNext
Loop
End If
Set fld = Nothing
Set rst = Nothing
Set db = Nothing
cmdHTML.Visible = True
'cmdHTML.Enabled = True
MsgBox "La procédure d'exportation est correctement terminée..."
End Sub
Private Sub recherche_Click()
On Error GoTo Err_recherche_Click
If Not IsNumeric(txtRecherche) Or Trim(txtRecherche) = "" Then
MsgBox "Vous n'avez pas tapé un numéro valide !"
Exit Sub
End If
' Screen.PreviousControl.SetFocus
' DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Fiche"
stLinkCriteria = "`N/REF` = " & txtRecherche
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_recherche_Click:
Exit Sub
Err_recherche_Click:
MsgBox Err.Description
Resume Exit_recherche_Click
End Sub
Private Sub Command40_Click()
On Error GoTo Err_Command40_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Euréponge"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Command40_Click:
Exit Sub
Err_Command40_Click:
MsgBox Err.Description
Resume Exit_Command40_Click
End Sub |
Partager