{"id":257,"date":"2025-07-30T19:58:59","date_gmt":"2025-07-30T19:58:59","guid":{"rendered":"https:\/\/loufab.alwaysdata.net\/blogaccess\/?p=257"},"modified":"2025-07-30T19:58:59","modified_gmt":"2025-07-30T19:58:59","slug":"vba-la-recherche-et-les-accents-en-sql-et-vba-2","status":"publish","type":"post","link":"https:\/\/loufab.alwaysdata.net\/blogaccess\/index.php\/2025\/07\/30\/vba-la-recherche-et-les-accents-en-sql-et-vba-2\/","title":{"rendered":"VBA : La recherche et les accents en SQL et VBA."},"content":{"rendered":"\n<p>Rechercher dans une base de donn\u00e9es avec l\u2019op\u00e9rateur Like est assez trivial. Avec quelques jokers on arrive \u00e0 retrouver ce que l\u2019on souhaite. Cependant&nbsp;lorsque on a affaire&nbsp;\u00e0 des&nbsp;contenus ayant des caract\u00e8res accentu\u00e9s il est difficile de r\u00e9cup\u00e9rer \u00e0 la fois ceux qui en comporte et ceux qui n\u2019en ont pas.<\/p>\n\n\n\n<p>L\u2019objet de ce billet est d\u2019utiliser VBA pour contourner ce probl\u00e8me.<\/p>\n\n\n\n<p>La premi\u00e8re chose \u00e0 faire est de cr\u00e9er une fonction qui va traiter le mot recherch\u00e9.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"visualbasic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Function ConvertAccForLike(strValue As String) As String\n' Fabrice Constans (MVP ACCESS) mars 2016\nIf InStr(1, strValue, \"a\") > 0 Then\n    strValue = Replace(strValue, \"a\", \"[a\u00e0\u00e2\u00e4]\")\nEnd If\nIf InStr(1, strValue, \"e\") > 0 Then\n    strValue = Replace(strValue, \"e\", \"[e\u00e9\u00e8\u00ea\u00eb]\")\nEnd If\nIf InStr(1, strValue, \"i\") > 0 Then\n    strValue = Replace(strValue, \"i\", \"[i\u00ee\u00ef]\")\nEnd If\nIf InStr(1, strValue, \"o\") > 0 Then\n    strValue = Replace(strValue, \"o\", \"[o\u00f4\u00f6]\")\nEnd If\nIf InStr(1, strValue, \"u\") > 0 Then\n    strValue = Replace(strValue, \"u\", \"[u\u00f9\u00fb\u00fc]\")\nEnd If\nConvertAccForLike = strValue\nEnd Function<\/pre>\n\n\n\n<p>Dans cette fonction, on recherche la pr\u00e9sence des voyelles, une \u00e0 une, en commen\u00e7ant par le a, ensuite le e, puis le i, etc. Chaque fois que la voyelle est d\u00e9tect\u00e9e on la remplace par la syntaxe Contient de l\u2019op\u00e9rateur Like, soit [\u2026]<\/p>\n\n\n\n<p>Pour le mot \u00ab\u00a0eleve\u00a0\u00bb, la valeur renvoy\u00e9e sera :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"visualbasic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"[e\u00e9\u00e8\u00ea\u00eb]l[e\u00e9\u00e8\u00ea\u00eb]v[e\u00e9\u00e8\u00ea\u00eb]\"<\/pre>\n\n\n\n<p>Les mots trouv\u00e9s seront :<\/p>\n\n\n\n<p><strong>eleve, \u00e9leve, \u00e9l\u00e8ve, \u00e9lev\u00e9\u2026<\/strong><\/p>\n\n\n\n<p>Vous pouvez l\u2019utiliser directement dans objet requ\u00eate, une source de formulaire, une clause <strong>Where <\/strong>d\u2019un\u00a0<strong>OpenForm <\/strong>ou <strong>OpenReport <\/strong>comme dans une requ\u00eate en VBA.<\/p>\n\n\n\n<p>Voici son utilisation :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT * FROM matable WHERE champ1 LIKE convertAccForLike(\"eleve\");<\/pre>\n\n\n\n<p>\u00c9videmment vous pouvez compl\u00e9ter avec les autres jokers.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT * FROM matable WHERE champ1 LIKE convertAccForLike(\"eleve?\");<\/pre>\n\n\n\n<p>Dans ce cas la valeur renvoy\u00e9e sera :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"visualbasic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\"[e\u00e9\u00e8\u00ea\u00eb]l[e\u00e9\u00e8\u00ea\u00eb]v[e\u00e9\u00e8\u00ea\u00eb]?\"<\/pre>\n\n\n\n<p>Ce bout de code fonctionne avec des tables li\u00e9es, cependant lorsque vous utilisez d&rsquo;autres bases de donn\u00e9es comme Sql Server, MariaDB, PostgreSql, il vaut mieux travailler directement sur ces derni\u00e8res pour des raisons \u00e9videntes de performance.<\/p>\n\n\n\n<p>N&rsquo;h\u00e9sitez pas \u00e0 laisser un commentaire.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rechercher dans une base de donn\u00e9es avec l\u2019op\u00e9rateur Like est assez trivial. Avec quelques jokers on arrive \u00e0 retrouver ce que l\u2019on souhaite. Cependant&nbsp;lorsque on a affaire&nbsp;\u00e0 des&nbsp;contenus ayant des caract\u00e8res accentu\u00e9s il est difficile de r\u00e9cup\u00e9rer \u00e0 la fois &hellip; <a href=\"https:\/\/loufab.alwaysdata.net\/blogaccess\/index.php\/2025\/07\/30\/vba-la-recherche-et-les-accents-en-sql-et-vba-2\/\">Continuer la lecture <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,6],"tags":[11,7],"class_list":["post-257","post","type-post","status-publish","format-standard","hentry","category-access","category-code-vba","tag-access","tag-code-vba"],"_links":{"self":[{"href":"https:\/\/loufab.alwaysdata.net\/blogaccess\/index.php\/wp-json\/wp\/v2\/posts\/257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/loufab.alwaysdata.net\/blogaccess\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/loufab.alwaysdata.net\/blogaccess\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/loufab.alwaysdata.net\/blogaccess\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/loufab.alwaysdata.net\/blogaccess\/index.php\/wp-json\/wp\/v2\/comments?post=257"}],"version-history":[{"count":5,"href":"https:\/\/loufab.alwaysdata.net\/blogaccess\/index.php\/wp-json\/wp\/v2\/posts\/257\/revisions"}],"predecessor-version":[{"id":262,"href":"https:\/\/loufab.alwaysdata.net\/blogaccess\/index.php\/wp-json\/wp\/v2\/posts\/257\/revisions\/262"}],"wp:attachment":[{"href":"https:\/\/loufab.alwaysdata.net\/blogaccess\/index.php\/wp-json\/wp\/v2\/media?parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/loufab.alwaysdata.net\/blogaccess\/index.php\/wp-json\/wp\/v2\/categories?post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/loufab.alwaysdata.net\/blogaccess\/index.php\/wp-json\/wp\/v2\/tags?post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}