Accueil > > > POUR SE SIMPLIFIER LES APPELS BASE DE DONNÉE ACCESS
POUR SE SIMPLIFIER LES APPELS BASE DE DONNÉE ACCESS
Information sur la source
Description
Je poste, (car je n'ai encore rien posté, et c'est pas juste !) un module .bas que j'ai créé (et que j'amende projets après projets) il y a bien 10 ans et que j'utilise très régulièrement Il y a quelques fonctions très utiles (OpenRecord et ExecuteSQL) après avoir renseigné le nom de la Base dans la constante NomBase (déclarations) Ces deux fonctions appellent Connect qui sauvegarde une copie de sécu de la base à chaque ouverture (au bout de 25 copies sur le disque, la fonction vous demande si vous voulez les effacer) après vous avoir demandé le chemin d'accès pour la toute première connexion. La fonction sauve ce chemin dans la base de registre et ne vous le demandera donc plus, sauf s'il ne trouve aucune base au chemin indiqué. Bon les autres fonctions, vous en faites ce que vous voulez : gStrTraduitQuote est très utile pour gérer les guillemets simples, gStrTraduitNumerique pour gérer les points décimaux, à vous de voir
Source
- Option Explicit
- Global pWrkJet As Workspace
- Global gMainDB As Database
- Private pBooSaved As Boolean
- Const NomBase = "FACT.mdb" ' Renseigner ici le nom de la base Access
-
-
- Private Const SWP_NOMOVE = &H2
- Private Const SWP_NOSIZE = &H1
- Private Const SWP_NOACTIVATE = &H10
- Private Const SWP_SHOWWINDOW = &H40
- Private Const HWND_TOPMOST = -1
- Private Const HWND_NOTOPMOST = -2
- Private Const HWND_FLAGS = SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
-
- Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
- Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wparam As Long, lParam As Long) As Long
-
-
-
- Const pStrMessage = "Désolé, le logiciel a rencontré un problème grave. Veuillez vous adresser à votre administrateur"
-
- Public Function ExecuteSQL(pStrSQL As String) As Boolean
- Dim linti As Long
-
- On Error GoTo ErrorHandler
- If pStrSQL <> "" Then
-
- If Connect Then
- Screen.MousePointer = vbHourglass
- StillExecute:
-
- gMainDB.Execute pStrSQL
-
- ExecuteSQL = True
-
- Else
- MsgBox "Base de donnée déconnectée. Redémarrer l'application", vbCritical, "Erreur d'objet"
- End If
-
- End If
- Sortie:
- Screen.MousePointer = vbDefault
- Exit Function
-
- ErrorHandler:
-
- Dim pErr As Error
-
- Select Case Err ' err.description
- Case 3667
- 'Une opération différente empèche l'exécution de cette opération.
- 'cette operation n'est pas autorisée en ce moment -> il faut tester stillexecuting
- Resume StillExecute 'ceci est fait maintenant par BusyTest
-
- Case 3146, 3147, 3148, 3149, 3150, 3151, 3152, 3153, 65535, 3669, 63535
- ' 3146 echec de l'appel err.description, 3669 Execution annulée
- 'ProcessErreur 10012
- 'il serait interressant de connaitre l erreur !!!
- 'For Each pErr In Errors
- ' If Err.Number <> 3146 Then
- ' ErrorLog pErr.Number & " - " & pErr.Description
- ' End If
- 'Next
- Resume Sortie 'il vaudrait mieux reporter l'erreur err.description errors.count
-
- Case 3154
- 'impossible de trouver la dll <nom>
- Case 3155, 3156, 3157, 3247
- 'pour les tables liées
- Case 3231
- 'champs trop long, données tronquées
- Case 3232
- 'impossible de créer une table -> ne doit pas arriver
- Case 3234
- 'expiration du délai d'attente -> à vérifier en connexion à distance
- Case 3235
- 'type de donnée non gérée par le serveur
- Case 3238
- 'donnée inexistante
- Case 3254
- 'impossible de verrouiller les enregistrements
- End Select
-
- 'pWrkJet.Rollback
-
- 'ErrorLog Err.Description
- Resume Sortie
- End Function
- Public Function gStrTraduitQuote(ByVal StrTexte As String) As String
- Dim pStrTexte As String
- Dim linti As Long
-
- 'je traduis 1 quote en 2 quote et je laisse 2 ou plus quotes telles quelles
- If StrTexte <> "" Then
- linti = InStr(StrTexte, "'")
- Do While linti > 0
- pStrTexte = pStrTexte & Left(StrTexte, linti) & "'"
- StrTexte = Right(StrTexte, Len(StrTexte) - linti)
- linti = InStr(StrTexte, "'")
- Loop
- gStrTraduitQuote = pStrTexte & StrTexte
- End If
- End Function
- Function NomFichier(StrNom As String) As String
- 'extrait le nom du fichier d'un chemin d'acces complet
- Dim Cmpt As Integer
-
-
- For Cmpt = Len(StrNom) To 1 Step -1
- If Mid$(StrNom, Cmpt, 1) = "/" Or Mid$(StrNom, Cmpt, 1) = "\" Then
- NomFichier = Right(StrNom, Len(StrNom) - Cmpt)
- Exit Function
- End If
- Next Cmpt
-
- NomFichier = StrNom
- End Function
- Public Function OpenRecord(ByVal sql As String, ByRef pRS As Recordset) As Boolean
- Dim linti As Long
- Dim pMouse As Long
-
- On Error GoTo ErrorHandler
-
- If sql <> "" Then
- If Connect Then
-
- StillExecute:
-
- Appel:
- pMouse = Screen.MousePointer
- Screen.MousePointer = vbHourglass
- Set pRS = gMainDB.OpenRecordset(sql, dbOpenDynaset)
-
- Screen.MousePointer = pMouse
- If Not pRS Is Nothing Then
- If pRS.RecordCount Then
- OpenRecord = True
- End If
- End If
- End If
-
- Sortie:
-
- Screen.MousePointer = pMouse
- End If
- Exit Function
-
- ErrorHandler:
- Dim pErr As Error
-
- Select Case Err
- Case 3667
- 'cette operation n'est pas autorisée en ce moment -> il faut tester stillexecuting Err.Description
- Resume StillExecute
-
- Case 3146, 3147, 3148, 3149, 3150, 3151, 3152, 3153, 65535, 3669, 63535
- ' 3146 echec de l'appel err.description, 3669 Execution annulée
- 'il serait interressant de connaitre l erreur !!!
- 'ProcessErreur 10012
- For Each pErr In Errors
- If pErr.Number <> 3146 Then
- 'ErrorLog pErr.Number & " - " & pErr.Description
- End If
- Next
- Resume Sortie 'il vaudrait mieux reporter l'erreur err.description errors.count
-
- Case 3154
- 'impossible de trouver la dll <nom>
- Case 3155, 3156, 3157, 3247
- 'pour les tables liées
- Case 3231
- 'champs trop long, données tronquées
- Case 3232
- 'impossible de créer une table -> ne doit pas arriver
- Case 3234
- 'expiration du délai d'attente -> à vérifier en connexion à distance
- Case 3235
- 'type de donnée non gérée par le serveur
- Case 3238
- 'donnée inexistante
- Case 3254
- 'impossible de verrouiller les enregistrements
-
- End Select
- 'ErrorLog Err.Description
- Resume Sortie
-
- End Function
- Public Function FormatRef(ByVal NewData As String) As String
- Dim linti As Long
- Dim pStrBuffer As String
-
- NewData = DeFormatRef(NewData)
- pStrBuffer = Mid(NewData, 1, 2) & " " & Mid(NewData, 3, 2) & " " & Mid(NewData, 5, 2)
- FormatRef = pStrBuffer
- End Function
- Public Function DeFormatRef(ByVal NewData As String) As String
- Dim linti As Long
- Dim pStrBuffer As String
-
- 'on déformate a partir de la gauche
- 'on ne fait qu'enlever les blancs
-
- linti = InStr(NewData, " ")
- Do Until linti = 0
- pStrBuffer = pStrBuffer & Left(NewData, linti - 1)
- NewData = Right(NewData, Len(NewData) - linti)
- linti = InStr(NewData, " ")
- Loop
-
- DeFormatRef = pStrBuffer & NewData
-
- End Function
- Public Function SetTopMostWindow(Window As Form, Topmost As Boolean) As Long
- If Topmost = True Then
- SetTopMostWindow = SetWindowPos(Window.hwnd, HWND_TOPMOST, 0, 0, 0, 0, HWND_FLAGS)
- Else
- SetTopMostWindow = SetWindowPos(Window.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, HWND_FLAGS)
- End If
- End Function
- Public Function Connect() As Boolean
- Dim pStrPath As String
- Dim pMouse As Long
-
- On Error GoTo ErrorHandler
-
- 'ouvre les bases
- pMouse = Screen.MousePointer
- If pWrkJet Is Nothing Then
- Screen.MousePointer = vbHourglass
- Set pWrkJet = CreateWorkspace("", "admin", "", dbUseJet)
- End If
-
- If gMainDB Is Nothing Then
- Screen.MousePointer = vbHourglass
- pStrPath = GetSetting("FACT", "DATA", "PATH", "")
- If pStrPath = "" Then
- GoTo ErrorHandler:
- End If
- If Not pBooSaved Then Save
- Set gMainDB = pWrkJet.OpenDatabase(pStrPath)
- Screen.MousePointer = pMouse
- End If
-
- Connect = True
- Exit Function
-
- ErrorHandler:
- If gMainDB Is Nothing Then
- Annexe.Recherche.ShowOpen
- pStrPath = Annexe.Recherche.FileName
- If pStrPath = NomBase Then
- Screen.MousePointer = vbDefault
- MsgBox "Impossible d'ouvrir la base de donnée", vbCritical, "Erreur d'objet"
- Connect = False
- Else
- SaveSetting "FACT", "DATA", "PATH", pStrPath
- If Not pBooSaved Then Save
- Set gMainDB = pWrkJet.OpenDatabase(pStrPath)
- Connect = True
- Screen.MousePointer = pMouse
- End If
- On Error GoTo 0
-
- Exit Function
- End If ' gMainDB.name gMainDB.connect err err.description app.path
-
- End Function
- Public Function GetMaintenant() As String
- GetMaintenant = Format(Now(), "dd/mm/yyyy")
- End Function
-
- Public Function gStrTraduitNumerique(ByVal pNum As Single) As String
- Dim pStrTexte As String, pStrNum As String
- Dim linti As Long
-
- pStrNum = Trim(pNum)
- linti = InStr(pStrNum, ",")
- Do While linti > 0
- pStrTexte = pStrTexte & Left(pStrNum, linti - 1) & "."
- pStrNum = Right(pStrNum, Len(pStrNum) - linti)
- linti = InStr(pStrNum, "'")
- Loop
- gStrTraduitNumerique = pStrTexte & pStrNum
-
- End Function
- Public Function FiltreChiffre(ByVal NewData) As String
- Dim pStr As String
-
- pStr = NewData
- Select Case pStr
- Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ","
- Case "."
- pStr = ","
- Case Else
- pStr = ""
- End Select
- FiltreChiffre = pStr
- End Function
- Public Function FiltreChiffreASCII(ByVal NewData) As String
- Dim pStr As String
-
- pStr = NewData
- Select Case pStr
- Case Asc("0"), Asc("1"), Asc("2"), Asc("3"), Asc("4"), Asc("5"), Asc("6"), Asc("7"), Asc("8"), Asc("9"), Asc(",")
- Case Asc(".")
- pStr = Asc(",")
- Case 8 'backspace
-
- Case Else
- pStr = 0
- End Select
- FiltreChiffreASCII = pStr
- End Function
- Public Function Today() As String
- Today = Right("0" & Day(Now), 2) & "/" & Right("0" & Month(Now), 2) & "/" & Year(Now)
- End Function
- Public Function Maj(ByVal pStrIn As String) As String
- 'retourne la string en minuscule avec la première lettre en majuscule
- 'et supprime les doublonds d'espace
- Dim linti As Long
-
-
- If pStrIn <> "" Then
- pStrIn = Trim(pStrIn)
- ' formate le nom pour avoir la première lettre en Maj et les autres en Min
- pStrIn = UCase(Left(pStrIn, 1)) & Right(pStrIn, Len(pStrIn) - 1)
- End If
- Maj = pStrIn
-
- End Function
- Private Sub Save()
- Dim pStrPath As String
- Dim pStrNom As String
- Dim pStrNewNom As String
- Dim plIntI As Long
- Dim plIntJ As Long
- Dim pBoo As Boolean
- Dim pNomBase As String
-
- On Error Resume Next
- pNomBase = UCase(Left(NomBase, Len(NomBase) - 4))
- pStrPath = GetSetting(pNomBase, "DATA", "PATH", "")
- pStrNom = Left(pStrPath, InStr(pStrPath, ".") - 1)
-
- Do Until pBoo
- pStrNewNom = pStrNom & "_" & Trim(plIntI) & ".sav"
- If Dir(pStrNewNom) = "" Then
- FileCopy pStrPath, pStrNewNom
- pBoo = True
- End If
- plIntI = plIntI + 1
- Loop
- If plIntI >= 26 Then
- If MsgBox("Il y a plus de 25 bases " & pNomBase & " sauvegardées, voulez-vous supprimer les 24 premières bases ?", vbInformation + vbYesNo, "Bases sauvegardées") = vbYes Then
- plIntI = plIntI - 1
- FileCopy pStrNom & "_" & plIntI & ".sav", pStrNom & "_0.sav"
- plIntJ = plIntI
- Do Until plIntJ = 0
- pStrNewNom = pStrNom & "_" & Trim(plIntJ) & ".sav"
- If Dir(pStrNewNom) <> "" Then
- Kill pStrNewNom
- End If
- plIntJ = plIntJ - 1
- Loop
- End If
- End If
-
- End Sub
-
- Public Function GetDerFact() As Long
- Dim pRS As Recordset
- Dim pStrSQL As String
- Dim pVarPreviousCle As String
-
-
- pStrSQL = "SELECT DER_FACTURE FROM T_Dernier"
- If OpenRecord(pStrSQL, pRS) Then
- GetDerFact = pRS!DER_FACTURE
- Else
- MsgBox pStrMessage, vbCritical, "Erreur d'objet"
- 'il y a un probleme, la cle vaudra 0 !
- End If
-
- End Function
-
-
- Public Function GetNewFact() As Long
- Dim pRS As Recordset
- Dim pStrSQL As String
- Dim pVarPreviousCle As String
-
- pVarPreviousCle = GetDerFact
- pStrSQL = "UPDATE T_Dernier SET DER_FACTURE =" & Trim(CLng(pVarPreviousCle) + 1)
- ExecuteSQL pStrSQL
- pStrSQL = "SELECT DER_FACTURE FROM T_Dernier"
- If OpenRecord(pStrSQL, pRS) Then
- GetNewFact = pRS!DER_FACTURE
- Else
- MsgBox pStrMessage, vbCritical, "Erreur d'objet"
- 'il y a un probleme, la cle vaudra 0 !
- End If
-
- End Function
- Public Function GetNewCle() As Long
- Dim pRS As Recordset
- Dim pStrSQL As String
- Dim pVarPreviousCle As String
-
-
- pStrSQL = "SELECT DER_CLE FROM T_Dernier"
- If OpenRecord(pStrSQL, pRS) Then
- pVarPreviousCle = pRS!DER_CLE
- pStrSQL = "UPDATE T_Dernier SET DER_CLE =" & Trim(CLng(pVarPreviousCle) + 1)
- ExecuteSQL pStrSQL
- pStrSQL = "SELECT DER_CLE FROM T_Dernier"
- If OpenRecord(pStrSQL, pRS) Then
- GetNewCle = pRS!DER_CLE
- Else
- MsgBox pStrMessage, vbCritical, "Erreur d'objet"
- 'il y a un probleme, la cle vaudra 0 !
- End If
- Else
- MsgBox pStrMessage, vbCritical, "Erreur d'objet"
- 'il y a un probleme, la cle vaudra 0 !
- End If
- End Function
-
Option Explicit
Global pWrkJet As Workspace
Global gMainDB As Database
Private pBooSaved As Boolean
Const NomBase = "FACT.mdb" ' Renseigner ici le nom de la base Access
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const HWND_FLAGS = SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wparam As Long, lParam As Long) As Long
Const pStrMessage = "Désolé, le logiciel a rencontré un problème grave. Veuillez vous adresser à votre administrateur"
Public Function ExecuteSQL(pStrSQL As String) As Boolean
Dim linti As Long
On Error GoTo ErrorHandler
If pStrSQL <> "" Then
If Connect Then
Screen.MousePointer = vbHourglass
StillExecute:
gMainDB.Execute pStrSQL
ExecuteSQL = True
Else
MsgBox "Base de donnée déconnectée. Redémarrer l'application", vbCritical, "Erreur d'objet"
End If
End If
Sortie:
Screen.MousePointer = vbDefault
Exit Function
ErrorHandler:
Dim pErr As Error
Select Case Err ' err.description
Case 3667
'Une opération différente empèche l'exécution de cette opération.
'cette operation n'est pas autorisée en ce moment -> il faut tester stillexecuting
Resume StillExecute 'ceci est fait maintenant par BusyTest
Case 3146, 3147, 3148, 3149, 3150, 3151, 3152, 3153, 65535, 3669, 63535
' 3146 echec de l'appel err.description, 3669 Execution annulée
'ProcessErreur 10012
'il serait interressant de connaitre l erreur !!!
'For Each pErr In Errors
' If Err.Number <> 3146 Then
' ErrorLog pErr.Number & " - " & pErr.Description
' End If
'Next
Resume Sortie 'il vaudrait mieux reporter l'erreur err.description errors.count
Case 3154
'impossible de trouver la dll <nom>
Case 3155, 3156, 3157, 3247
'pour les tables liées
Case 3231
'champs trop long, données tronquées
Case 3232
'impossible de créer une table -> ne doit pas arriver
Case 3234
'expiration du délai d'attente -> à vérifier en connexion à distance
Case 3235
'type de donnée non gérée par le serveur
Case 3238
'donnée inexistante
Case 3254
'impossible de verrouiller les enregistrements
End Select
'pWrkJet.Rollback
'ErrorLog Err.Description
Resume Sortie
End Function
Public Function gStrTraduitQuote(ByVal StrTexte As String) As String
Dim pStrTexte As String
Dim linti As Long
'je traduis 1 quote en 2 quote et je laisse 2 ou plus quotes telles quelles
If StrTexte <> "" Then
linti = InStr(StrTexte, "'")
Do While linti > 0
pStrTexte = pStrTexte & Left(StrTexte, linti) & "'"
StrTexte = Right(StrTexte, Len(StrTexte) - linti)
linti = InStr(StrTexte, "'")
Loop
gStrTraduitQuote = pStrTexte & StrTexte
End If
End Function
Function NomFichier(StrNom As String) As String
'extrait le nom du fichier d'un chemin d'acces complet
Dim Cmpt As Integer
For Cmpt = Len(StrNom) To 1 Step -1
If Mid$(StrNom, Cmpt, 1) = "/" Or Mid$(StrNom, Cmpt, 1) = "\" Then
NomFichier = Right(StrNom, Len(StrNom) - Cmpt)
Exit Function
End If
Next Cmpt
NomFichier = StrNom
End Function
Public Function OpenRecord(ByVal sql As String, ByRef pRS As Recordset) As Boolean
Dim linti As Long
Dim pMouse As Long
On Error GoTo ErrorHandler
If sql <> "" Then
If Connect Then
StillExecute:
Appel:
pMouse = Screen.MousePointer
Screen.MousePointer = vbHourglass
Set pRS = gMainDB.OpenRecordset(sql, dbOpenDynaset)
Screen.MousePointer = pMouse
If Not pRS Is Nothing Then
If pRS.RecordCount Then
OpenRecord = True
End If
End If
End If
Sortie:
Screen.MousePointer = pMouse
End If
Exit Function
ErrorHandler:
Dim pErr As Error
Select Case Err
Case 3667
'cette operation n'est pas autorisée en ce moment -> il faut tester stillexecuting Err.Description
Resume StillExecute
Case 3146, 3147, 3148, 3149, 3150, 3151, 3152, 3153, 65535, 3669, 63535
' 3146 echec de l'appel err.description, 3669 Execution annulée
'il serait interressant de connaitre l erreur !!!
'ProcessErreur 10012
For Each pErr In Errors
If pErr.Number <> 3146 Then
'ErrorLog pErr.Number & " - " & pErr.Description
End If
Next
Resume Sortie 'il vaudrait mieux reporter l'erreur err.description errors.count
Case 3154
'impossible de trouver la dll <nom>
Case 3155, 3156, 3157, 3247
'pour les tables liées
Case 3231
'champs trop long, données tronquées
Case 3232
'impossible de créer une table -> ne doit pas arriver
Case 3234
'expiration du délai d'attente -> à vérifier en connexion à distance
Case 3235
'type de donnée non gérée par le serveur
Case 3238
'donnée inexistante
Case 3254
'impossible de verrouiller les enregistrements
End Select
'ErrorLog Err.Description
Resume Sortie
End Function
Public Function FormatRef(ByVal NewData As String) As String
Dim linti As Long
Dim pStrBuffer As String
NewData = DeFormatRef(NewData)
pStrBuffer = Mid(NewData, 1, 2) & " " & Mid(NewData, 3, 2) & " " & Mid(NewData, 5, 2)
FormatRef = pStrBuffer
End Function
Public Function DeFormatRef(ByVal NewData As String) As String
Dim linti As Long
Dim pStrBuffer As String
'on déformate a partir de la gauche
'on ne fait qu'enlever les blancs
linti = InStr(NewData, " ")
Do Until linti = 0
pStrBuffer = pStrBuffer & Left(NewData, linti - 1)
NewData = Right(NewData, Len(NewData) - linti)
linti = InStr(NewData, " ")
Loop
DeFormatRef = pStrBuffer & NewData
End Function
Public Function SetTopMostWindow(Window As Form, Topmost As Boolean) As Long
If Topmost = True Then
SetTopMostWindow = SetWindowPos(Window.hwnd, HWND_TOPMOST, 0, 0, 0, 0, HWND_FLAGS)
Else
SetTopMostWindow = SetWindowPos(Window.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, HWND_FLAGS)
End If
End Function
Public Function Connect() As Boolean
Dim pStrPath As String
Dim pMouse As Long
On Error GoTo ErrorHandler
'ouvre les bases
pMouse = Screen.MousePointer
If pWrkJet Is Nothing Then
Screen.MousePointer = vbHourglass
Set pWrkJet = CreateWorkspace("", "admin", "", dbUseJet)
End If
If gMainDB Is Nothing Then
Screen.MousePointer = vbHourglass
pStrPath = GetSetting("FACT", "DATA", "PATH", "")
If pStrPath = "" Then
GoTo ErrorHandler:
End If
If Not pBooSaved Then Save
Set gMainDB = pWrkJet.OpenDatabase(pStrPath)
Screen.MousePointer = pMouse
End If
Connect = True
Exit Function
ErrorHandler:
If gMainDB Is Nothing Then
Annexe.Recherche.ShowOpen
pStrPath = Annexe.Recherche.FileName
If pStrPath = NomBase Then
Screen.MousePointer = vbDefault
MsgBox "Impossible d'ouvrir la base de donnée", vbCritical, "Erreur d'objet"
Connect = False
Else
SaveSetting "FACT", "DATA", "PATH", pStrPath
If Not pBooSaved Then Save
Set gMainDB = pWrkJet.OpenDatabase(pStrPath)
Connect = True
Screen.MousePointer = pMouse
End If
On Error GoTo 0
Exit Function
End If ' gMainDB.name gMainDB.connect err err.description app.path
End Function
Public Function GetMaintenant() As String
GetMaintenant = Format(Now(), "dd/mm/yyyy")
End Function
Public Function gStrTraduitNumerique(ByVal pNum As Single) As String
Dim pStrTexte As String, pStrNum As String
Dim linti As Long
pStrNum = Trim(pNum)
linti = InStr(pStrNum, ",")
Do While linti > 0
pStrTexte = pStrTexte & Left(pStrNum, linti - 1) & "."
pStrNum = Right(pStrNum, Len(pStrNum) - linti)
linti = InStr(pStrNum, "'")
Loop
gStrTraduitNumerique = pStrTexte & pStrNum
End Function
Public Function FiltreChiffre(ByVal NewData) As String
Dim pStr As String
pStr = NewData
Select Case pStr
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ","
Case "."
pStr = ","
Case Else
pStr = ""
End Select
FiltreChiffre = pStr
End Function
Public Function FiltreChiffreASCII(ByVal NewData) As String
Dim pStr As String
pStr = NewData
Select Case pStr
Case Asc("0"), Asc("1"), Asc("2"), Asc("3"), Asc("4"), Asc("5"), Asc("6"), Asc("7"), Asc("8"), Asc("9"), Asc(",")
Case Asc(".")
pStr = Asc(",")
Case 8 'backspace
Case Else
pStr = 0
End Select
FiltreChiffreASCII = pStr
End Function
Public Function Today() As String
Today = Right("0" & Day(Now), 2) & "/" & Right("0" & Month(Now), 2) & "/" & Year(Now)
End Function
Public Function Maj(ByVal pStrIn As String) As String
'retourne la string en minuscule avec la première lettre en majuscule
'et supprime les doublonds d'espace
Dim linti As Long
If pStrIn <> "" Then
pStrIn = Trim(pStrIn)
' formate le nom pour avoir la première lettre en Maj et les autres en Min
pStrIn = UCase(Left(pStrIn, 1)) & Right(pStrIn, Len(pStrIn) - 1)
End If
Maj = pStrIn
End Function
Private Sub Save()
Dim pStrPath As String
Dim pStrNom As String
Dim pStrNewNom As String
Dim plIntI As Long
Dim plIntJ As Long
Dim pBoo As Boolean
Dim pNomBase As String
On Error Resume Next
pNomBase = UCase(Left(NomBase, Len(NomBase) - 4))
pStrPath = GetSetting(pNomBase, "DATA", "PATH", "")
pStrNom = Left(pStrPath, InStr(pStrPath, ".") - 1)
Do Until pBoo
pStrNewNom = pStrNom & "_" & Trim(plIntI) & ".sav"
If Dir(pStrNewNom) = "" Then
FileCopy pStrPath, pStrNewNom
pBoo = True
End If
plIntI = plIntI + 1
Loop
If plIntI >= 26 Then
If MsgBox("Il y a plus de 25 bases " & pNomBase & " sauvegardées, voulez-vous supprimer les 24 premières bases ?", vbInformation + vbYesNo, "Bases sauvegardées") = vbYes Then
plIntI = plIntI - 1
FileCopy pStrNom & "_" & plIntI & ".sav", pStrNom & "_0.sav"
plIntJ = plIntI
Do Until plIntJ = 0
pStrNewNom = pStrNom & "_" & Trim(plIntJ) & ".sav"
If Dir(pStrNewNom) <> "" Then
Kill pStrNewNom
End If
plIntJ = plIntJ - 1
Loop
End If
End If
End Sub
Public Function GetDerFact() As Long
Dim pRS As Recordset
Dim pStrSQL As String
Dim pVarPreviousCle As String
pStrSQL = "SELECT DER_FACTURE FROM T_Dernier"
If OpenRecord(pStrSQL, pRS) Then
GetDerFact = pRS!DER_FACTURE
Else
MsgBox pStrMessage, vbCritical, "Erreur d'objet"
'il y a un probleme, la cle vaudra 0 !
End If
End Function
Public Function GetNewFact() As Long
Dim pRS As Recordset
Dim pStrSQL As String
Dim pVarPreviousCle As String
pVarPreviousCle = GetDerFact
pStrSQL = "UPDATE T_Dernier SET DER_FACTURE =" & Trim(CLng(pVarPreviousCle) + 1)
ExecuteSQL pStrSQL
pStrSQL = "SELECT DER_FACTURE FROM T_Dernier"
If OpenRecord(pStrSQL, pRS) Then
GetNewFact = pRS!DER_FACTURE
Else
MsgBox pStrMessage, vbCritical, "Erreur d'objet"
'il y a un probleme, la cle vaudra 0 !
End If
End Function
Public Function GetNewCle() As Long
Dim pRS As Recordset
Dim pStrSQL As String
Dim pVarPreviousCle As String
pStrSQL = "SELECT DER_CLE FROM T_Dernier"
If OpenRecord(pStrSQL, pRS) Then
pVarPreviousCle = pRS!DER_CLE
pStrSQL = "UPDATE T_Dernier SET DER_CLE =" & Trim(CLng(pVarPreviousCle) + 1)
ExecuteSQL pStrSQL
pStrSQL = "SELECT DER_CLE FROM T_Dernier"
If OpenRecord(pStrSQL, pRS) Then
GetNewCle = pRS!DER_CLE
Else
MsgBox pStrMessage, vbCritical, "Erreur d'objet"
'il y a un probleme, la cle vaudra 0 !
End If
Else
MsgBox pStrMessage, vbCritical, "Erreur d'objet"
'il y a un probleme, la cle vaudra 0 !
End If
End Function
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Petite question sur les barre d'outil personalise sous access 2000! !! [ par jcconi ]
je voudrai savoir comment faire pour masquer tel ou tel bouton de ma barre d'outil en VBA sous un projet access 2000merci!!!!
SQLserver EXPRESS [ par tolt ]
Bonjour, Juste uen petite question pratique. Je découvre cette outil formidable et gratuit soit SQLserver EXPRESS qui est une merveille et qui enfin
Audit d'une base ACCESS [ par Litderose ]
Bonjour,Ce n'est pas forcément le bon forum mais je tente le coup : je dois "auditer" une dizaine de base Access développées par divers intervenants.
Outil efficace de réparation d'une base de données ACCESS [ par sigmatc24 ]
Bonjour,De temps à autre et vu que j'ai développé une application utilisant ACCESS 97, il arrive que cette dernière soit tellement corrompu qu'il devi
Comment controler une saisie d'un utilisateur dans une base access [ par sanndr ]
Bonjour ! Je suis un débutant en VB6 et access et je cherche à controler la saisie d'un utilisateur ( zone de saisie) pour savoir si elle n'existe pa
Conseils pour débutant Access 2010 [ par ocz255 ]
Salut à tous, je dois mettre en place un outil de gestion de clients, de prise de rendez-vous, et d'information relatifs aux clients ( avec documents
listview vers access [ par noureddineaouadi ]
Bonjour, je veux un code qui fait le mise a jour d'une table access suite a la suppression d'une ligne d'un liste listview et merci.
Base ACCESS VEROUILLER? [ par ANAGO ]
salut j'ai telecharger une base de donnees pour un depot de boisson siur ce site mais je ne peut pas acceder a la base access car elle est verouiller
gestion des intervalle de dates provenant de la BD Access avec VBNet [ par ManuelFabio ]
j'ai entrer des informations dans ma BD Access et j'aimerai les sélectionner en fonction des date que l'utilisateur aura choisi (date1<date2 ).afin d'
Vb.net [ par anasei ]
Bonjour, j'ai une base de donnee access et je veux creer une forme sur vb.net 2008 qui permet de : quand j'ecris un nom d'une personne sachant que c
|
Derniers Blogs
XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Je m'y prends un peu tard je sais, mais bon je suis développeur web et donc hyper fainéant ! Toujours dans le cadre des technologies émergentes, ici HTML5, parce qu'on aime HTML5 chez Wyg , nous seront présent, le vieux ( Aurélien V.) et moi, pour pr...
Cliquez pour lire la suite de l'article par Gio [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
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate 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
|