Bonjour,
je rencontre qq problèmes dans ma base de données access à cause des apostrophes:
- je ne peux pas avoir de fiches avec des apostrophes dans les champs car le logiciel ne me les accepte pas dans la recherche:
voilà le code:
Code:
[/cpp]Private Sub Commande29_Click()
Dim recRecherche As DAO.Recordset
Dim reqRecherche As String
Dim marqueur As Integer
marqueur = 0
'requete de base pour la recherche
'reqRecherche = "SELECT Entreprises.[Raison sociale], Entreprises.Adresse, Entreprises.[Adresse 2], " & _
" Entreprises.[Code postal], Entreprises.Ville, Entreprises.Pays, Interlocuteurs.Titre, Interlocuteurs.[Nom interlocuteur], Interlocuteurs.Prénom,Interlocuteurs.Fonction, " & _
" Entreprises.[Type de relation], Contrats.Type, Contacts.Intéret, Contacts.[Date du contact]," & _
" Contrats.Date FROM ((Entreprises LEFT JOIN Contrats ON Entreprises.[Raison sociale] = Contrats.Société)" & _
" LEFT JOIN Interlocuteurs ON Entreprises.[Raison sociale] = Interlocuteurs.Société) " & _
" LEFT JOIN Contacts ON Interlocuteurs.[Nom interlocuteur] = Contacts.Interlocuteur " & _
" GROUP BY Entreprises.[Raison sociale], Entreprises.Adresse, Entreprises.[Adresse 2], " & _
" Entreprises.[Code postal], Entreprises.Ville, Entreprises.Pays, Interlocuteurs.Fonction, " & _
" Entreprises.[Type de relation], Contrats.Type, Contacts.Intéret, Contacts.[Date du contact], " & _
" Contrats.Date "
reqRecherche = "SELECT Entreprises.[Raison sociale], Entreprises.Adresse, Entreprises.[Adresse 2], " & _
" Entreprises.[Code postal], Entreprises.Ville, Entreprises.Pays, Interlocuteurs.Titre, " & _
" Interlocuteurs.[Nom interlocuteur], Interlocuteurs.Prénom, Interlocuteurs.Fonction, " & _
" Entreprises.[Type de relation], Contrats.Type, Contacts.Intéret, Contacts.[Date du contact], " & _
" Contrats.Date " & _
" FROM ((Entreprises LEFT JOIN Contrats ON Entreprises.[Raison sociale] = Contrats.Société) " & _
" LEFT JOIN Interlocuteurs ON Entreprises.[Raison sociale] = Interlocuteurs.Société) " & _
" LEFT JOIN Contacts ON Interlocuteurs.[Nom interlocuteur] = Contacts.Interlocuteur" & _
" GROUP BY Entreprises.[Raison sociale], Entreprises.Adresse, Entreprises.[Adresse 2], " & _
" Entreprises.[Code postal], Entreprises.Ville, Entreprises.Pays, Interlocuteurs.Titre, " & _
" Interlocuteurs.[Nom interlocuteur], Interlocuteurs.Prénom, Interlocuteurs.Fonction, " & _
" Entreprises.[Type de relation], Contrats.Type, Contacts.Intéret, Contacts.[Date du contact]," & _
" Contrats.Date"
'concatenation des criteres des recherche
If Me.Rech_Fonction <> "" Then
reqRecherche = "" & reqRecherche & " HAVING(((Interlocuteurs.Fonction) = '" & Me.Rech_Fonction & "')) "
marqueur = 1
End If
If Me.Rech_TypeRel <> "" Then
reqRecherche = "" & reqRecherche & "" & IIf(marqueur = 1, Me.txt_ANDOR_typerel, " HAVING " ) & "(((Entreprises.[Type de relation]) = '" & Me.Rech_TypeRel & "')) "
If marqueur <> 1 Then
marqueur = 1
End If
End If
If Me.Rech_TypeContrat <> "" Then
reqRecherche = "" & reqRecherche & "" & IIf(marqueur = 1, Me.txt_ANDOR_typecontrat, " HAVING " ) & " (((Contrats.Type) = '" & Me.Rech_TypeContrat & "')) "
If marqueur <> 1 Then
marqueur = 1
End If
End If
If Me.Rech_IntPot <> "" Then
reqRecherche = "" & reqRecherche & "" & IIf(marqueur = 1, Me.txt_ANDOR_intPot, " HAVING " ) & " (((Contacts.Intéret) = '" & Me.Rech_IntPot & "'))"
If marqueur <> 1 Then
marqueur = 1
End If
End If
If Me.Rech_IntPot1 <> "" Then
reqRecherche = "" & reqRecherche & "" & IIf(marqueur = 1, Me.txt_ANDOR_intPot1, " HAVING " ) & " (((Contacts.Intéret) = '" & Me.Rech_IntPot1 & "'))"
If marqueur <> 1 Then
marqueur = 1
End If
End If
If Me.Rech_IntPot2 <> "" Then
reqRecherche = "" & reqRecherche & "" & IIf(marqueur = 1, Me.txt_ANDOR_intPot2, " HAVING " ) & " (((Contacts.Intéret) = '" & Me.Rech_IntPot2 & "'))"
If marqueur <> 1 Then
marqueur = 1
End If
End If
If Me.Rech_DateContactDebut <> "" And Me.Rech_DateContactFin <> "" Then
reqRecherche = "" & reqRecherche & "" & IIf(marqueur = 1, Me.txt_ANDOR_DateContact, " HAVING " ) & " (((Contacts.[Date du contact]) Between #" & Me.Rech_DateContactDebut & "# And #" & Me.Rech_DateContactFin & "#))"
If marqueur <> 1 Then
marqueur = 1
End If
End If
If Me.Rech_DateContratDebut <> "" And Me.Rech_DateContratFin <> "" Then
reqRecherche = "" & reqRecherche & "" & IIf(marqueur = 1, Me.txt_ANDOR_DateContrat, " HAVING " ) & "(((Contrats.Date) Between #" & Me.Rech_DateContratDebut & "# And #" & Me.Rech_DateContratFin & "#))"
End If
'Afficher la ligne suivante pour débugger au cas où la requête ne fonctionne pas
'MsgBox "" & reqRecherche
Set recRecherche = CurrentDb.OpenRecordset(reqRecherche)
'Insertion des résultats dans la table T_RESULTATRECHERCHE
CurrentDb.Execute ("DELETE * FROM T_RESULTATRECHERCHE" )
While recRecherche.EOF <> True
CurrentDb.Execute ("INSERT INTO T_RESULTATRECHERCHE([Raison sociale],[Adresse],[Adresse 2],[Code Postal],[Ville],[Pays],[Titre],[Nom interlocuteur],[Prénom]) " & _
" VALUES('" & recRecherche![Raison sociale] & "','" & recRecherche!Adresse & "','" & recRecherche![Adresse 2] & "'," & _
"'" & recRecherche![Code postal] & "','" & recRecherche![Ville] & "','" & recRecherche![Pays] & "'," & _
"'" & recRecherche![Titre] & "','" & recRecherche![Nom interlocuteur] & "','" & recRecherche![Prénom] & "')" )
recRecherche.MoveNext
Wend
'affichage des résultats
If MsgBox("Voulez vous afficher les résultats ?", vbYesNo, "Résultats de la recherche" ) = vbYes Then
DoCmd.OpenQuery "T_RESULTATRECHERCHE Requête"
End If
End Sub
Code :
- - je rencontre également ce problème dans un code sur un bouton qui utilise un champ
- voici le code:
- Code:
- [cpp]Private Sub contacts_Click()
- On Error GoTo Err_contacts_Click
- Dim stDocName As String
- Dim stLinkCriteria As String
- stDocName = "Interlocuteurs"
- stLinkCriteria = "Interlocuteurs.Société = '" & Me.Raison_sociale & "'"
- DoCmd.OpenForm stDocName, , , stLinkCriteria
- Exit_contacts_Click:
- Exit Sub
- Err_contacts_Click:
- MsgBox Err.Description
- Resume Exit_contacts_Click
-
- End Sub
|
Que peut-on faire?
Merci d'avance