<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Philben - Ms Access &#187; Date</title>
	<atom:link href="https://blog.developpez.com/philben/ptag/date/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/philben</link>
	<description></description>
	<lastBuildDate>Thu, 26 Sep 2013 19:43:53 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>VBA : Date de fin d&#8217;une période</title>
		<link>https://blog.developpez.com/philben/p12245/vba-access/vba-date-de-fin-dune-periode</link>
		<comments>https://blog.developpez.com/philben/p12245/vba-access/vba-date-de-fin-dune-periode#comments</comments>
		<pubDate>Sat, 21 Sep 2013 09:24:50 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Algorithme]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=817</guid>
		<description><![CDATA[Pour faire suite au billet précédent, cette fonction retourne la date de fin de la période choisie (mois, bimestre, trimestre, quadrimestre, semestre et année). La fonction Public Function DateFinPeriode(ByVal DateRef As Date, ByVal Periode As Integer) As Date &#160; &#160;Select &#8230; <a href="https://blog.developpez.com/philben/p12245/vba-access/vba-date-de-fin-dune-periode">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Pour faire suite au <a href="http://blog.developpez.com/philben/p12244/vba-access/vba-date-de-debut-dune-periode" title="VBA : Date de début d’une période" target="_blank">billet précédent</a>, cette fonction retourne la date de fin de la période choisie (mois, bimestre, trimestre, quadrimestre, semestre et année).<br />
<span id="more-817"></span><br />
<strong>La fonction</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> DateFinPeriode(<span style="color: #151B8D; font-weight: bold;">ByVal</span> DateRef <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> Periode <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Select</span> <span style="color: #8D38C9; font-weight: bold;">Case</span> Periode<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Case</span> 1, 2, 3, 4, 6, 12<br />
&nbsp; &nbsp; &nbsp; DateFinPeriode = DateSerial(Year(DateRef), Int((Month(DateRef) - 1) / Periode) * Periode + Periode + 1, 0)<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">Select</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Exemples</strong><br />
Des exemples à exécuter dans la fenêtre ‘Exécution’ (Ctrl+G) de l’éditeur VBA (Alt+F11).</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">?DateFinPeriode(#2013/09/20#,1) <span style="color: #008000;">'Mois -&gt; 30/09/2013 <br />
</span>?DateFinPeriode(#2013/09/20#,2) <span style="color: #008000;">'Bimestre -&gt; 31/10/2013 <br />
</span>?DateFinPeriode(#2013/09/20#,3) <span style="color: #008000;">'Trimestre -&gt; 30/09/2013<br />
</span>?DateFinPeriode(#2013/09/20#,4) <span style="color: #008000;">'Quadrimestre -&gt; 31/12/2013 <br />
</span>?DateFinPeriode(#2013/09/20#,6) <span style="color: #008000;">'Semestre -&gt; 31/12/2013 <br />
</span>?DateFinPeriode(#2013/09/20#,12) 'Annuelle -&gt; 31/12/2013</div></div>
<p>&nbsp;<br />
<strong>Vérification</strong><br />
Résultats dans la fenêtre &lsquo;Exécution&rsquo;</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TestFinPeriode()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, y <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, s <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, c <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, r <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, d <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> v <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Variant</span>, aDerDate(0 <span style="color: #8D38C9; font-weight: bold;">To</span> 5) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, aCpt(0 <span style="color: #8D38C9; font-weight: bold;">To</span> 5) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, bErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp;<span style="color: #008000;">'vba.Array retourne toujours un tableau de base zéro (indépendance vis à vis de Option Base) contrairement à Array()<br />
</span> &nbsp; <span style="color: #008000;">'Mais en règle générale, on utilise Array()<br />
</span> &nbsp; v = VBA.Array(1, 2, 3, 4, 6, 12)<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;Randomize<br />
&nbsp; &nbsp;y = Int(3000 * Rnd) + 100<br />
<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Année aléatoire : &quot;</span> &amp; y<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Mois&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Mensuel(1)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot;Bimestre(2)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Trimes.(3)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Quadri.(4)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot;Semestre(6)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Année(12)&quot;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #008000;">'affecte une date initiale non interférente<br />
</span> &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> j = <span style="color: #151B8D; font-weight: bold;">LBound</span>(aDerDate) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(aDerDate): aDerDate(j) = #5/15/2000#: <span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 12<br />
&nbsp; &nbsp; &nbsp; r = DateSerial(y, i, Int(28 * Rnd) + 1) &nbsp; &nbsp;<span style="color: #008000;">'28 maxi pour février...<br />
</span> &nbsp; &nbsp; &nbsp;s = Format(r, <span style="color: #800000;">&quot;mm &nbsp;&quot;</span>) &amp; vbTab<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> j = <span style="color: #151B8D; font-weight: bold;">LBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(v)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;d = DateFinPeriode(r, v(j))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> d &lt;&gt; aDerDate(j) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c = <span style="color: #800000;">&quot;*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> Month(d) &lt;&gt; Month(aDerDate(j)) <span style="color: #8D38C9; font-weight: bold;">And</span> Year(d) = y <span style="color: #8D38C9; font-weight: bold;">Then</span> aCpt(j) = aCpt(j) + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c = <span style="color: #800000;">&quot; &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s = s &amp; c &amp; d &amp; vbTab<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aDerDate(j) = d<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> s<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = <span style="color: #151B8D; font-weight: bold;">LBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(v)<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> aCpt(i) &lt;&gt; 12 \ v(i) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Erreur détectée pour la période n°&quot;</span> &amp; (i + 1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bErr = <span style="color: #00C2FF; font-weight: bold;">True</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #8D38C9; font-weight: bold;">Not</span> bErr <span style="color: #8D38C9; font-weight: bold;">Then</span> Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Aucune erreur détectée...&quot;</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;</p>
<p>@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA : Date de début d&#8217;une période</title>
		<link>https://blog.developpez.com/philben/p12244/vba-access/vba-date-de-debut-dune-periode</link>
		<comments>https://blog.developpez.com/philben/p12244/vba-access/vba-date-de-debut-dune-periode#comments</comments>
		<pubDate>Fri, 20 Sep 2013 19:11:39 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Algorithme]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=807</guid>
		<description><![CDATA[Je vous présente une fonction qui retourne, en fonction de la date passée en paramètre et la période choisie (Mois, Bimestre, Trimestre, Quadrimestre, Semestre ou Année), la première date de cette période. La fonction Public Function DateDebutPeriode(ByVal DateRef As Date, &#8230; <a href="https://blog.developpez.com/philben/p12244/vba-access/vba-date-de-debut-dune-periode">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Je vous présente une fonction qui retourne, en fonction de la date passée en paramètre et la période choisie (Mois, Bimestre, Trimestre, Quadrimestre, Semestre ou Année), la première date de cette période.<br />
<span id="more-807"></span><br />
<strong>La fonction</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> DateDebutPeriode(<span style="color: #151B8D; font-weight: bold;">ByVal</span> DateRef <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> Periode <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
<span style="color: #008000;">'Philben - v1.0 - Free to use<br />
</span> &nbsp; <span style="color: #8D38C9; font-weight: bold;">Select</span> <span style="color: #8D38C9; font-weight: bold;">Case</span> Periode<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Case</span> 1, 2, 3, 4, 6, 12<br />
&nbsp; &nbsp; &nbsp; DateDebutPeriode = DateSerial(Year(DateRef), Int((Month(DateRef) - 1) / Periode) * Periode + 1, 1)<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">Select</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Paramètres</strong><br />
Le premier paramètre est la date de référence de la période, le deuxième indique le type de période : 1 pour mensuelle, 2 pour bimestrielle, 3 pour trimestrielle, 4 pour quadrimestrielle, 6 pour semestrielle et 12 pour annuelle.</p>
<p>Il y a donc dans une année, 12 périodes mensuelles, 6 bimestres, 4 trimestres, 3 quadrimestres, 2 semestres.</p>
<p><strong>Exemples</strong><br />
Des exemples à exécuter dans fenêtre &lsquo;Exécution&rsquo; (Ctrl+G) de l&rsquo;éditeur VBA (Alt+F11).</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">?DateDebutPeriode(#2013/09/20#,1) <span style="color: #008000;">'Mois -&gt; 01/09/2013 <br />
</span><br />
?DateDebutPeriode(#2013/08/20#,2) <span style="color: #008000;">'Bimestre -&gt; 01/07/2013 <br />
</span>?DateDebutPeriode(#2013/09/20#,2) <span style="color: #008000;">'Bimestre -&gt; 01/09/2013 <br />
</span><br />
?DateDebutPeriode(#2013/09/20#,3) <span style="color: #008000;">'Trimestre -&gt; 01/07/2013<br />
</span>?DateDebutPeriode(#2013/08/20#,4) <span style="color: #008000;">'Quadrimestre -&gt; 01/05/2013 <br />
</span>?DateDebutPeriode(#2013/09/20#,6) <span style="color: #008000;">'Semestre -&gt; 01/07/2013 <br />
</span>?DateDebutPeriode(#2013/09/20#,12) 'Annuelle -&gt; 01/01/2013</div></div>
<p>&nbsp;<br />
<strong>Vérification</strong><br />
Cette fonction teste chaque période pour chaque mois d&rsquo;une année choisie aléatoirement.<br />
Un astérisque avant une date indique un changement de période.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TestDebutPeriode()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, y <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, s <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, c <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, r <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, d <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> v <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Variant</span>, aDerDate(0 <span style="color: #8D38C9; font-weight: bold;">To</span> 5) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, aCpt(0 <span style="color: #8D38C9; font-weight: bold;">To</span> 5) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, bErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span><br />
<br />
&nbsp; &nbsp;v = VBA.Array(1, 2, 3, 4, 6, 12)<br />
&nbsp; &nbsp;Randomize<br />
&nbsp; &nbsp;y = Int(3000 * Rnd) + 100<br />
<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Année aléatoire : &quot;</span> &amp; y<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Mois&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Mensuel(1)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot;Bimestre(2)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Trimes.(3)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Quadri.(4)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot;Semestre(6)&quot;</span> &amp; vbTab &amp; <span style="color: #800000;">&quot; Année(12)&quot;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 12<br />
&nbsp; &nbsp; &nbsp; r = DateSerial(y, i, Int(28 * Rnd) + 1) &nbsp; <span style="color: #008000;">'28 maxi pour février...<br />
</span> &nbsp; &nbsp; &nbsp;s = Format(r, <span style="color: #800000;">&quot;mm &nbsp;&quot;</span>) &amp; vbTab<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> j = <span style="color: #151B8D; font-weight: bold;">LBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(v)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;d = DateDebutPeriode(r, v(j))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> d &lt;&gt; aDerDate(j) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c = <span style="color: #800000;">&quot;*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> Day(d) = 1 <span style="color: #8D38C9; font-weight: bold;">And</span> Year(d) = y <span style="color: #8D38C9; font-weight: bold;">Then</span> aCpt(j) = aCpt(j) + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c = <span style="color: #800000;">&quot; &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s = s &amp; c &amp; d &amp; vbTab<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aDerDate(j) = d<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> s<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = <span style="color: #151B8D; font-weight: bold;">LBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(v)<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> aCpt(i) &lt;&gt; 12 \ v(i) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Erreur détectée pour la période n°&quot;</span> &amp; (i + 1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bErr = <span style="color: #00C2FF; font-weight: bold;">True</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
<br />
&nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #8D38C9; font-weight: bold;">Not</span> bErr <span style="color: #8D38C9; font-weight: bold;">Then</span> Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Aucune erreur détectée...&quot;</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA : S&#8217;agit-il d&#8217;un jour ouvré non chômé ?</title>
		<link>https://blog.developpez.com/philben/p12194/vba-access/sagit-il-dun-jour-ouvre-non-chome</link>
		<comments>https://blog.developpez.com/philben/p12194/vba-access/sagit-il-dun-jour-ouvre-non-chome#comments</comments>
		<pubDate>Tue, 27 Aug 2013 21:12:21 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Jour de semaine]]></category>
		<category><![CDATA[Jour férié]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=683</guid>
		<description><![CDATA[La fonction VBA présentée dans ce billet permet de savoir si la date passée en argument correspond à un jour ouvré (du lundi au vendredi) non chômé (non férié) en France. Dépendances de la fonction Nécessite la fonction EstJourFerie() et &#8230; <a href="https://blog.developpez.com/philben/p12194/vba-access/sagit-il-dun-jour-ouvre-non-chome">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La fonction VBA présentée dans ce billet permet de savoir si la date passée en argument correspond à un jour ouvré (du lundi au vendredi) non chômé (non férié) en France.<br />
<span id="more-683"></span><br />
<strong>Dépendances de la fonction</strong><br />
Nécessite la fonction <a href="http://blog.developpez.com/philben/p11458/vba-access/sagit-il-dun-jour-ferie" title="S’agit-il d’un jour férié ?" target="_blank">EstJourFerie()</a> et la fonction <a href="http://blog.developpez.com/philben/p11431/vba-access/calculer-la-date-de-paques" title="Calculer la date de Pâques" target="_blank">Paques()</a>.</p>
<p><strong>Le code de la fonction</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> EstJourOuvreNonChome(<span style="color: #151B8D; font-weight: bold;">ByVal</span> laDate <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, <span style="color: #151B8D; font-weight: bold;">Optional</span> <span style="color: #151B8D; font-weight: bold;">ByVal</span> EstPentecoteChome <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span> = <span style="color: #00C2FF; font-weight: bold;">True</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span><br />
<span style="color: #008000;">'Retourne Vrai si la date est un jour ouvré (du lundi au vendredi) NON férié (non chômé)<br />
</span><span style="color: #008000;">'philben - free to use<br />
</span> &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> Weekday(laDate, vbMonday) &lt; 6 <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #8D38C9; font-weight: bold;">Not</span> EstJourFerie(laDate, EstPentecoteChome) <span style="color: #8D38C9; font-weight: bold;">Then</span> EstJourOuvreNonChome = <span style="color: #00C2FF; font-weight: bold;">True</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Explications</strong><br />
La fonction retourne <strong>Vrai</strong> si la date passée en argument correspond à un jour ouvré non chômé.<br />
Cette fonction admet un deuxième paramètre qui permet de définir si le jour de la Pentecôte est chômé (Vrai par défaut) ou non.</p>
<p>La ligne de code <strong>&lsquo;If Weekday(&#8230;)&rsquo;</strong> filtre les jours de semaine pour ne conserver que les jours ouvrés (du lundi au vendredi). On utilise ensuite la fonction EstJourFerie(&#8230;) qui retourne Vrai s&rsquo;il s&rsquo;agit d&rsquo;un jour férié.</p>
<p><strong>Vérification des résultats</strong><br />
La fonction suivante compte les jours ouvrés non chômés pour différentes années puis compare le résultat avec la valeur attendue (données issues de <a href="http://www.joursouvres.fr/" target="_blank">ce site</a>).</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TestEstJourOuvreNonChome()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> v() <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Variant</span>, d <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, l <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, NbErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span><br />
<br />
&nbsp; &nbsp;v = Array(2010, 254, 2011, 253, 2012, 253, 2013, 251, 2014, 251, 2015, 252, 2016, 253, 2021, 254)<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = <span style="color: #151B8D; font-weight: bold;">LBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">To</span> <span style="color: #151B8D; font-weight: bold;">UBound</span>(v) <span style="color: #8D38C9; font-weight: bold;">Step</span> 2<br />
&nbsp; &nbsp; &nbsp; d = DateSerial(v(i), 1, 1)<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">While</span> Year(d) = v(i)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> EstJourOuvreNonChome(d) <span style="color: #8D38C9; font-weight: bold;">Then</span> l = l + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;d = d + 1<br />
&nbsp; &nbsp; &nbsp; Wend<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> l &lt;&gt; v(i + 1) <span style="color: #8D38C9; font-weight: bold;">Then</span> NbErr = NbErr + 1<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Nb jours ouvrés non chômés en &quot;</span> &amp; v(i), <span style="color: #800000;">&quot; -&gt; Attendu : &quot;</span> &amp; v(i + 1), <span style="color: #800000;">&quot; -&gt; Obtenu : &quot;</span> &amp; l, IIf(l &lt;&gt; v(i + 1), <span style="color: #800000;">&quot;*** ERREUR ***&quot;</span>, <span style="color: #800000;">&quot;&quot;</span>)<br />
&nbsp; &nbsp; &nbsp; l = 0<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Nombre d'erreur(s) : &quot;</span> &amp; NbErr<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>Remarque : Le lundi de Pentecôte est considéré comme chômé ici.</p>
<p>@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>VBA : Date d&#8217;un premier jour de semaine du mois</title>
		<link>https://blog.developpez.com/philben/p12179/vba-access/vba-date-dun-premier-jour-de-semaine-du-mois</link>
		<comments>https://blog.developpez.com/philben/p12179/vba-access/vba-date-dun-premier-jour-de-semaine-du-mois#comments</comments>
		<pubDate>Thu, 15 Aug 2013 13:56:40 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Jour de semaine]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=654</guid>
		<description><![CDATA[Episode VI de la saga &#8216;Weekday&#8217;. Cette fois-ci, on introduit la notion de mois puisque l&#8217;on souhaite obtenir la date d&#8217;un premier jour de semaine du mois de la date de référence. Quelle est la date du premier dimanche du &#8230; <a href="https://blog.developpez.com/philben/p12179/vba-access/vba-date-dun-premier-jour-de-semaine-du-mois">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Episode <strong>VI</strong> de la saga &lsquo;Weekday&rsquo;. Cette fois-ci, on introduit la notion de <strong>mois</strong> puisque l&rsquo;on souhaite obtenir la date d&rsquo;un premier jour de semaine du mois de la date de référence. Quelle est la date du premier dimanche du mois ? La date du premier lundi du mois ?<br />
<span id="more-654"></span><br />
<strong>Préambule</strong><br />
Je vous conseille de lire le <a href="http://blog.developpez.com/philben/p11417/vba-access/date-du-jour-de-semaine-suivant" title="Date du jour de semaine suivant" target="_blank">premier billet de &lsquo;Weekday&rsquo;</a> pour comprendre le principe des calculs.<br />
Voir aussi le <a href="http://blog.developpez.com/philben/p12177/vba-access/vba-recapitulatif-des-fonctions-jour-de-semaine" title="VBA : Récapitulatif des fonctions ‘jour de semaine’" target="_blank">récapitulatif</a> des fonctions.</p>
<p><strong>La fonction VBA</strong><br />
Nécessite la fonction <a href="http://blog.developpez.com/philben/p11417/vba-access/date-du-jour-de-semaine-suivant" title="Date du jour de semaine suivant">DateJourSuivant()</a></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> DateJourDebutMois(<span style="color: #151B8D; font-weight: bold;">ByVal</span> DateRef <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> Jour <span style="color: #151B8D; font-weight: bold;">As</span> VbDayOfWeek) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;DateJourDebutMois = DateJourSuivant(DateRef - Day(DateRef), Jour)<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>Pour atteindre rapidement le dernier jour du mois précédent, on soustrait à la date de référence son jour du mois. Par exemple le 15 août &#8211; 15 donnera le 31 juillet.<br />
On recherche ensuite le jour de semaine souhaité qui suit le dernier jour du mois précédent grâce à notre fonction DateJourSuivant().</p>
<p><strong>Tester la fonction</strong><br />
Affiche les résultats dans la fenêtre ‘Exécution’ de l’éditeur VB.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TestDateJourDebutMois()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> s <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, d <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, dm <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, djdm <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, NbErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span><br />
<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Test DateJourDebutMois()&quot;</span> &amp; vbCrLf &amp; <span style="color: #800000;">&quot;----------------------&quot;</span><br />
<br />
&nbsp; &nbsp;d = Int(Now())<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">While</span> Weekday(d) &lt;&gt; vbMonday: d = d + 1: Wend<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;* Semaine de référence du &quot;</span> &amp; Format(d, <span style="color: #800000;">&quot;dddd dd/mm/yyyy&quot;</span>) &amp; <span style="color: #800000;">&quot; au &quot;</span> &amp; Format(d + 6, <span style="color: #800000;">&quot;dddd dd/mm/yyyy&quot;</span>)<br />
<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7<br />
&nbsp; &nbsp; &nbsp; dm = DateSerial(Year(d), Month(d), 1)<br />
&nbsp; &nbsp; &nbsp; j = i <span style="color: #151B8D; font-weight: bold;">Mod</span> 7 + 1<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">While</span> Weekday(dm) &lt;&gt; j: dm = dm + 1: Wend<br />
<br />
&nbsp; &nbsp; &nbsp; djdm = DateJourDebutMois(d, Weekday(d))<br />
&nbsp; &nbsp; &nbsp; s = s &amp; vbTab &amp; <span style="color: #800000;">&quot;-&gt; Jour recherché : &quot;</span> &amp; Format(dm, <span style="color: #800000;">&quot;ddd dd/mm/yyyy&quot;</span>) &amp; <span style="color: #800000;">&quot; - Jour trouvé : &quot;</span> &amp; Format(djdm, <span style="color: #800000;">&quot;ddd dd/mm/yyyy&quot;</span>) &amp; vbCrLf<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> djdm &lt;&gt; dm <span style="color: #8D38C9; font-weight: bold;">Then</span> NbErr = NbErr + 1<br />
&nbsp; &nbsp; &nbsp; d = d + 1<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> s &amp; <span style="color: #800000;">&quot;***&quot;</span> &amp; IIf(NbErr &gt; 0, NbErr, <span style="color: #800000;">&quot; Aucune&quot;</span>) &amp; <span style="color: #800000;">&quot; erreur(s) commise(s) ***&quot;</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
@+ pour la suite des épisodes ‘Weekday’.</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA : S&#8217;agit-il d&#8217;un jour de week-end ?</title>
		<link>https://blog.developpez.com/philben/p12178/vba-access/vba-sagit-il-dun-jour-de-week-end</link>
		<comments>https://blog.developpez.com/philben/p12178/vba-access/vba-sagit-il-dun-jour-de-week-end#comments</comments>
		<pubDate>Thu, 15 Aug 2013 11:55:58 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Jour de semaine]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=637</guid>
		<description><![CDATA[Une petite fonction qui permet de savoir si la date passée en argument correspond à une jour de week-end ou non. La fonction VBA Public Function EstWeekEnd(ByVal dDate As Date) As Boolean &#160; &#160;If Weekday(dDate, vbMonday) &#62; 5 Then EstWeekEnd &#8230; <a href="https://blog.developpez.com/philben/p12178/vba-access/vba-sagit-il-dun-jour-de-week-end">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Une petite fonction qui permet de savoir si la date passée en argument correspond à une jour de week-end ou non.<br />
<span id="more-637"></span><br />
<strong>La fonction VBA</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> EstWeekEnd(<span style="color: #151B8D; font-weight: bold;">ByVal</span> dDate <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> Weekday(dDate, vbMonday) &gt; 5 <span style="color: #8D38C9; font-weight: bold;">Then</span> EstWeekEnd = <span style="color: #00C2FF; font-weight: bold;">True</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
Elle retourne <strong>Vrai</strong> si la date est un samedi ou un dimanche sinon elle renvoie <strong>Faux</strong> par défaut.</p>
<p><strong>Principe</strong><br />
On impose à &lsquo;Weekday()&rsquo; que le 1er jour de semaine est le lundi (constante &lsquo;vbMonday&rsquo;) et non le dimanche par défaut. Ainsi, le 6ème et le 7ème jour sont le samedi et le dimanche.</p>
<p><strong>Exemples</strong><br />
Dans la fenêtre Exécution du VBE.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">?EstWeekEnd(#2013/8/16#) <span style="color: #008000;">'Vendredi 16 août 2013 : Faux<br />
</span>?EstWeekEnd(#2013/8/17#) <span style="color: #008000;">'Samedi 17 août 2013 : Vrai<br />
</span>?EstWeekEnd(#2013/8/18#) <span style="color: #008000;">'Dimanche 18 août 2013 : Vrai<br />
</span>?EstWeekEnd(#2013/8/19#) 'Lundi 19 août 2013 : Faux</div></div>
<p>&nbsp;</p>
<p>@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA : Récapitulatif des fonctions &#8216;jour de semaine&#8217;</title>
		<link>https://blog.developpez.com/philben/p12177/vba-access/vba-recapitulatif-des-fonctions-jour-de-semaine</link>
		<comments>https://blog.developpez.com/philben/p12177/vba-access/vba-recapitulatif-des-fonctions-jour-de-semaine#comments</comments>
		<pubDate>Thu, 15 Aug 2013 11:15:36 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Jour de semaine]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=623</guid>
		<description><![CDATA[Dans ces exemples, on recherche la date d&#8217;un mercredi. Le mercredi avec une croix rouge indique le mercredi retourné selon la fonction utilisée et le jour de la date de référence. DateJourSemaineEnCours() renvoie toujours la date du mercredi de la &#8230; <a href="https://blog.developpez.com/philben/p12177/vba-access/vba-recapitulatif-des-fonctions-jour-de-semaine">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><img src="http://philben.developpez.com/Weekday.png" alt="Recapitulatif weekday" /><br />
<span id="more-623"></span><br />
Dans ces exemples, on recherche la date d&rsquo;un mercredi. Le mercredi avec une croix rouge indique le mercredi retourné selon la fonction utilisée et le jour de la date de référence.</p>
<ul>
<li><a href="http://blog.developpez.com/philben/p11481/vba-access/date-dun-jour-de-la-semaine-courante" title="Date d’un jour de la semaine courante" target="_blank">DateJourSemaineEnCours()</a> renvoie toujours la date du mercredi de la semaine quelque soit le jour de la date de référence</li>
<li><a href="http://blog.developpez.com/philben/p11470/vba-access/date-du-jour-meme-ou-precedent" title="Date du jour-même ou précédent" target="_blank">DateJourMemeOuPrecedent()</a> renvoie la date du mercredi qui précède la date de référence ou la date de référence elle-même s&rsquo;il s&rsquo;agit d&rsquo;un mercredi</li>
<li><a href="http://blog.developpez.com/philben/p11454/vba-access/date-du-jour-de-semaine-precedent" title="Date du jour de semaine précédent" target="_blank">DateJourPrecedent()</a> renvoie la date du mercredi qui précède la date de référence</li>
<li><a href="http://blog.developpez.com/philben/p11438/vba-access/date-du-jour-meme-ou-suivant" title="Date du jour-même ou suivant" target="_blank">DateJourMemeOuSuivant()</a> renvoie la date du mercredi qui suit la date de référence ou la date de référence elle-même s&rsquo;il s&rsquo;agit d&rsquo;un mercredi</li>
<li><a href="http://blog.developpez.com/philben/p11417/vba-access/date-du-jour-de-semaine-suivant" title="Date du jour de semaine suivant" target="_blank">DateJourSuivant()</a> renvoie la date du mercredi qui suit la date de référence</li>
</ul>
<p><strong>Remarque</strong><br />
Les fonctions décrites peuvent provoquer une erreur (dépassement de capacité &#8211; Erreur n°6) :</p>
<ul>
<li>si on passe une date proche du 1er janvier de l&rsquo;an 100 aux fonctions ayant un balayage arrière</li>
<li>si on passe une date proche du 31 décembre 9999 aux fonctions ayant un balayage avant</li>
</ul>
<p>En effet, on peut dépasser dans ces cas, la plage des dates autorisées par Access. Pour ne pas lever cette erreur, vous pouvez introduire un gestionnaire d&rsquo;erreur dans les fonctions.</p>
<p>@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date d&#8217;un jour de la semaine courante</title>
		<link>https://blog.developpez.com/philben/p11481/vba-access/date-dun-jour-de-la-semaine-courante</link>
		<comments>https://blog.developpez.com/philben/p11481/vba-access/date-dun-jour-de-la-semaine-courante#comments</comments>
		<pubDate>Thu, 08 Nov 2012 18:17:01 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Algorithme]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Jour de semaine]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=590</guid>
		<description><![CDATA[Episode V de la saga &#8216;Weekday&#8217;. Cette fois-ci, on introduit la notion de semaine puisque l&#8217;on souhaite obtenir la date d&#8217;un jour quelconque de la semaine de la date de référence. Quelle est la date du dimanche de cette semaine &#8230; <a href="https://blog.developpez.com/philben/p11481/vba-access/date-dun-jour-de-la-semaine-courante">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Episode <strong>V</strong> de la saga &lsquo;Weekday&rsquo;. Cette fois-ci, on introduit la notion de <strong>semaine</strong> puisque l&rsquo;on souhaite obtenir la date d&rsquo;un jour quelconque de la semaine de la date de référence. Quelle est la date du dimanche de cette semaine ? La date du mardi ?<br />
<span id="more-590"></span><br />
<strong>Préambule</strong><br />
Je vous conseille de lire le <a href="http://blog.developpez.com/philben/p11417/vba-access/date-du-jour-de-semaine-suivant" title="Date du jour de semaine suivant" target="_blank">premier billet de &lsquo;Weekday&rsquo;</a> pour comprendre le principe des calculs.<br />
Voir aussi le <a href="http://blog.developpez.com/philben/p12177/vba-access/vba-recapitulatif-des-fonctions-jour-de-semaine" title="VBA : Récapitulatif des fonctions ‘jour de semaine’" target="_blank">récapitulatif</a> des fonctions.</p>
<p><strong>Les matrices</strong><br />
On souhaite donc passer de la matrice &lsquo;Weekday&rsquo; à la matrice &lsquo;Jour de la semaine courante&rsquo;. Si le premier jour de semaine est un lundi (qui peut être le dimanche comme aux U.S.A.), la matrice finale est :</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Weekday(Date,VbDayOfWeek) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Jour de la semaine (1er jour : lundi)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VbDayOfWeek &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VbDayOfWeek &nbsp; &nbsp; &nbsp; &nbsp;<br />
Jour Date &nbsp;L &nbsp; M &nbsp; M &nbsp; J &nbsp; V &nbsp; S &nbsp; D &nbsp; &nbsp; &nbsp;Jour date &nbsp;L &nbsp; M &nbsp; M &nbsp; J &nbsp; V &nbsp; S &nbsp; D <br />
Lundi &nbsp; &nbsp; &nbsp;1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; &nbsp; &nbsp;Lundi &nbsp; &nbsp; &nbsp;0 &nbsp; 1 &nbsp; 2 &nbsp; 3 &nbsp; 4 &nbsp; 5 &nbsp; 6 <br />
Mardi &nbsp; &nbsp; &nbsp;2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; &nbsp; &nbsp;Mardi &nbsp; &nbsp; -1 &nbsp; 0 &nbsp; 1 &nbsp; 2 &nbsp; 3 &nbsp; 4 &nbsp; 5 <br />
Mercredi &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 vers Mercredi &nbsp;-2 &nbsp;-1 &nbsp; 0 &nbsp; 1 &nbsp; 2 &nbsp; 3 &nbsp; 4 <br />
Jeudi &nbsp; &nbsp; &nbsp;4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; &nbsp; &nbsp;Jeudi &nbsp; &nbsp; -3 &nbsp;-2 &nbsp;-1 &nbsp; 0 &nbsp; 1 &nbsp; 2 &nbsp; 3 <br />
Vendredi &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; &nbsp; &nbsp;Vendredi &nbsp;-4 &nbsp;-3 &nbsp;-2 &nbsp;-1 &nbsp; 0 &nbsp; 1 &nbsp; 2 <br />
Samedi &nbsp; &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; &nbsp; &nbsp;Samedi &nbsp; &nbsp;-5 &nbsp;-4 &nbsp;-3 &nbsp;-2 &nbsp;-1 &nbsp; 0 &nbsp; 1 <br />
Dimanche &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; &nbsp; &nbsp;Dimanche &nbsp;-6 &nbsp;-5 &nbsp;-4 &nbsp;-3 &nbsp;-2 &nbsp;-1 &nbsp; 0</div></div>
<p>&nbsp;<br />
On remarque que les valeurs sont symétriquement opposées par rapport à la diagonale. Pour pouvoir gérer tous les cas quelque soit le premier jour de semaine, le plus simple est de se servir de ce premier jour de semaine comme pivot.</p>
<p><strong>La fonction VBA</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> DateJourSemaineEnCours(<span style="color: #151B8D; font-weight: bold;">ByVal</span> DateRef <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> Jour <span style="color: #151B8D; font-weight: bold;">As</span> VbDayOfWeek, _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Optional</span> <span style="color: #151B8D; font-weight: bold;">ByVal</span> PremierJourDeSemaine <span style="color: #151B8D; font-weight: bold;">As</span> VbDayOfWeek = vbMonday) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;DateJourSemaineEnCours = DateRef + (Jour - CInt(Weekday(DateRef, PremierJourDeSemaine)) - PremierJourDeSemaine + 1)<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> Jour &lt; PremierJourDeSemaine <span style="color: #8D38C9; font-weight: bold;">Then</span> DateJourSemaineEnCours = DateJourSemaineEnCours + 7<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
La fonction admet trois paramètres : La date de référence et le jour de semaine recherché. Le troisième paramètre est optionnel (PremierJourDeSemaine) et contient sous forme de constante le nom du 1er jour de semaine. La valeur par défaut de ce paramètre est <strong>lundi</strong>.</p>
<p><strong>Tester la fonction</strong><br />
La fonction suivante teste les 49 x 7 possibilités des matrices et affiche les résultats dans la fenêtre ‘Exécution’ de l’éditeur VB.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TestDateJourSemaineEnCours()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> s <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, d <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, dates(1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, k <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, l <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, NbErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, SumErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span><br />
<br />
&nbsp; &nbsp;d = Int(Now())<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Test DateJourSemaineEnCours()&quot;</span> &amp; vbCrLf &amp; <span style="color: #800000;">&quot;----------------------&quot;</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> l = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7<br />
&nbsp; &nbsp; &nbsp; d = Int(Now())<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">While</span> Weekday(d) &lt;&gt; l: d = d + 1: Wend<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> k = 0 <span style="color: #8D38C9; font-weight: bold;">To</span> 6: dates(Weekday(d + k)) = d + k: <span style="color: #8D38C9; font-weight: bold;">Next</span> k<br />
<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;* Semaine du &quot;</span> &amp; Format(d, <span style="color: #800000;">&quot;dddd dd/mm/yyyy&quot;</span>) &amp; <span style="color: #800000;">&quot; au &quot;</span> &amp; Format(d + 6, <span style="color: #800000;">&quot;dddd dd/mm/yyyy&quot;</span>)<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NbErr = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s = vbTab &amp; <span style="color: #800000;">&quot;-&gt; Jour recherché : &quot;</span> &amp; Format(d + i - 1, <span style="color: #800000;">&quot;ddd dd/mm/yyyy&quot;</span>) &amp; <span style="color: #800000;">&quot; : &quot;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> j = 0 <span style="color: #8D38C9; font-weight: bold;">To</span> 6<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> DateJourSemaineEnCours(d + j, i, l) &lt;&gt; dates(i) <span style="color: #8D38C9; font-weight: bold;">Then</span> NbErr = NbErr + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> s &amp; IIf(NbErr &gt; 0, NbErr, <span style="color: #800000;">&quot; Aucune&quot;</span>) &amp; <span style="color: #800000;">&quot; erreur(s)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SumErr = SumErr + NbErr<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> l<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;***&quot;</span> &amp; IIf(SumErr &gt; 0, SumErr, <span style="color: #800000;">&quot; Aucune&quot;</span>) &amp; <span style="color: #800000;">&quot; erreur(s) commise(s) ***&quot;</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Exemples</strong><br />
A coller dans la fenêtre &lsquo;Exécution&rsquo; du VBE.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">'Date du dimanche pour la date donnée et pour une semaine commençant le lundi<br />
</span>?DateJourSemaineEnCours(#2012/11/8#,vbSunday) <span style="color: #008000;">'11/11/2012<br />
</span><span style="color: #008000;">'Date du lundi pour la date donnée et pour une semaine commençant le lundi<br />
</span>?DateJourSemaineEnCours(#2012/11/8#,vbMonday) <span style="color: #008000;">'05/11/2012<br />
</span><span style="color: #008000;">'Date du dimanche pour la date donnée et pour une semaine commençant le dimanche<br />
</span>?DateJourSemaineEnCours(#2012/11/8#,vbSunday,vbSunday) '04/11/2012</div></div>
<p>&nbsp;<br />
@+ pour la suite des épisodes ‘Weekday’.</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date du jour-même ou précédent</title>
		<link>https://blog.developpez.com/philben/p11470/vba-access/date-du-jour-meme-ou-precedent</link>
		<comments>https://blog.developpez.com/philben/p11470/vba-access/date-du-jour-meme-ou-precedent#comments</comments>
		<pubDate>Fri, 02 Nov 2012 11:53:31 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Algorithme]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Jour de semaine]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=585</guid>
		<description><![CDATA[Episode IV de la saga &#8216;Weekday&#8217;. On souhaite obtenir cette fois-ci, la date d&#8217;un jour de semaine qui précède ou NON la date de référence. Préambule Je vous conseille de lire le premier billet de &#8216;Weekday&#8217; pour comprendre le principe &#8230; <a href="https://blog.developpez.com/philben/p11470/vba-access/date-du-jour-meme-ou-precedent">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Episode <strong>IV</strong> de la saga &lsquo;Weekday&rsquo;. On souhaite obtenir cette fois-ci, la date d&rsquo;un jour de semaine qui précède ou <strong>NON</strong> la date de référence.<br />
<span id="more-585"></span><br />
<strong>Préambule</strong><br />
Je vous conseille de lire le <a href="http://blog.developpez.com/philben/p11417/vba-access/date-du-jour-de-semaine-suivant" title="Date du jour de semaine suivant" target="_blank">premier billet de &lsquo;Weekday&rsquo;</a> pour comprendre le principe des calculs.<br />
Voir aussi le <a href="http://blog.developpez.com/philben/p12177/vba-access/vba-recapitulatif-des-fonctions-jour-de-semaine" title="VBA : Récapitulatif des fonctions ‘jour de semaine’" target="_blank">récapitulatif</a> des fonctions.</p>
<p><strong>Les matrices</strong><br />
On souhaite donc passer de la matrice &lsquo;Weekday&rsquo; à la matrice &lsquo;Jour courant ou précédent&rsquo;</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Weekday(Date,VbDayOfWeek) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Jour courant ou précédent &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VbDayOfWeek &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VbDayOfWeek &nbsp; &nbsp; &nbsp; <br />
Jour Date &nbsp;L &nbsp; M &nbsp; M &nbsp; J &nbsp; V &nbsp; S &nbsp; D &nbsp; &nbsp; &nbsp; &nbsp;Jour date &nbsp;L &nbsp; M &nbsp; M &nbsp; J &nbsp; V &nbsp; S &nbsp; D<br />
Lundi &nbsp; &nbsp; &nbsp;1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp;Lundi &nbsp; &nbsp; &nbsp;0 &nbsp;-6 &nbsp;-5 &nbsp;-4 &nbsp;-3 &nbsp;-2 &nbsp;-1<br />
Mardi &nbsp; &nbsp; &nbsp;2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; &nbsp; &nbsp; &nbsp;Mardi &nbsp; &nbsp; -1 &nbsp; 0 &nbsp;-6 &nbsp;-5 &nbsp;-4 &nbsp;-3 &nbsp;-2<br />
Mercredi &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp;vers &nbsp;Mercredi &nbsp;-2 &nbsp;-1 &nbsp; 0 &nbsp;-6 &nbsp;-5 &nbsp;-4 &nbsp;-3<br />
Jeudi &nbsp; &nbsp; &nbsp;4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; &nbsp; &nbsp; &nbsp;Jeudi &nbsp; &nbsp; -3 &nbsp;-2 &nbsp;-1 &nbsp; 0 &nbsp;-6 &nbsp;-5 &nbsp;-4<br />
Vendredi &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; &nbsp; &nbsp; &nbsp;Vendredi &nbsp;-4 &nbsp;-3 &nbsp;-2 &nbsp;-1 &nbsp; 0 &nbsp;-6 &nbsp;-5<br />
Samedi &nbsp; &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; &nbsp; &nbsp; &nbsp;Samedi &nbsp; &nbsp;-5 &nbsp;-4 &nbsp;-3 &nbsp;-2 &nbsp;-1 &nbsp; 0 &nbsp;-6<br />
Dimanche &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp;Dimanche &nbsp;-6 &nbsp;-5 &nbsp;-4 &nbsp;-3 &nbsp;-2 &nbsp;-1 &nbsp; 0</div></div>
<p>&nbsp;<br />
On remarque que toutes les valeurs de la matrice finale sont les opposés + 1 de la matrice &lsquo;Weekday&rsquo;. Par exemple, si la date de référence est un lundi, le mardi sera 1 &#8211; 7 = -6, le dimanche sera 1 &#8211; 2 = -1 et pour les valeurs de la diagonale, la formule est 1 &#8211; 1 = 0.</p>
<p><strong>La fonction VBA</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> DateJourMemeOuPrecedent(<span style="color: #151B8D; font-weight: bold;">ByVal</span> DateRef <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> Jour <span style="color: #151B8D; font-weight: bold;">As</span> VbDayOfWeek) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;DateJourMemeOuPrecedent = DateRef - CInt(Weekday(DateRef, Jour)) + 1<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Tester la fonction</strong><br />
La fonction suivante teste les 49 possibilités de la matrice et affiche les résultats dans la fenêtre ‘Exécution’ de l’éditeur VB.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TestDateJourMemeOuPrecedent()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> d <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, r <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, dates(1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, k <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, NbErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> s <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, Jours <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Variant</span><br />
<br />
&nbsp; &nbsp;d = Int(Now())<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">While</span> Weekday(d) &lt;&gt; vbMonday: d = d + 1: Wend<br />
&nbsp; &nbsp;Jours = VBA.Array(<span style="color: #800000;">&quot;Dimanche&quot;</span>, <span style="color: #800000;">&quot;Lundi &nbsp; &quot;</span>, <span style="color: #800000;">&quot;Mardi &nbsp; &quot;</span>, <span style="color: #800000;">&quot;Mercredi&quot;</span>, <span style="color: #800000;">&quot;Jeudi &nbsp; &quot;</span>, <span style="color: #800000;">&quot;Vendredi&quot;</span>, <span style="color: #800000;">&quot;Samedi &nbsp;&quot;</span>)<br />
<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Test DateJourMêmeOuPrecedent()&quot;</span> &amp; vbCrLf &amp; <span style="color: #800000;">&quot;----------------------&quot;</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7<br />
&nbsp; &nbsp; &nbsp; s = vbNullString<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;* Date de référence : &quot;</span> &amp; Format(d, <span style="color: #800000;">&quot;dddd dd/mm/yyyy&quot;</span>)<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> vbTab &amp; <span style="color: #800000;">&quot;Jour cherché&quot;</span> &amp; vbTab &amp; vbTab &amp; <span style="color: #800000;">&quot;Jour trouvé&quot;</span> &amp; vbTab &amp; vbTab &amp; <span style="color: #800000;">&quot;Conforme ?&quot;</span> &amp; vbCrLf &amp; _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vbTab &amp; <span style="color: #800000;">&quot;----------------------------------------------&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> k = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 6: dates(Weekday(d - k)) = d - k: <span style="color: #8D38C9; font-weight: bold;">Next</span> k<br />
&nbsp; &nbsp; &nbsp; dates(Weekday(d)) = d<br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> j = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;r = DateJourMemeOuPrecedent(d, j)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s = s &amp; vbTab &amp; Jours(j - 1) &amp; vbTab &amp; vbTab &amp; Format(r, <span style="color: #800000;">&quot;ddd dd/mm/yyyy&quot;</span>) &amp; vbTab &amp; vbTab<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> r &lt;&gt; dates(j) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NbErr = NbErr + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s = s &amp; <span style="color: #800000;">&quot;Erreur !&quot;</span> &amp; vbCrLf<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s = s &amp; <span style="color: #800000;">&quot;Ok&quot;</span> &amp; vbCrLf<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> s<br />
&nbsp; &nbsp; &nbsp; d = d + 1<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;***&quot;</span> &amp; IIf(NbErr &gt; 0, NbErr, <span style="color: #800000;">&quot; Aucune&quot;</span>) &amp; <span style="color: #800000;">&quot; erreur(s) commise(s) ***&quot;</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
@+ pour la suite des épisodes ‘Weekday’.</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>S&#8217;agit-il d&#8217;un jour férié ?</title>
		<link>https://blog.developpez.com/philben/p11458/vba-access/sagit-il-dun-jour-ferie</link>
		<comments>https://blog.developpez.com/philben/p11458/vba-access/sagit-il-dun-jour-ferie#comments</comments>
		<pubDate>Sun, 28 Oct 2012 18:01:27 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Jour férié]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=560</guid>
		<description><![CDATA[Je vous présente une fonction écrite en VBA qui détermine si la date passée en argument correspond à un jour férié français ou non. La réponse est obtenue en moins d&#8217;un millionième de seconde ! Les jours fériés légaux en &#8230; <a href="https://blog.developpez.com/philben/p11458/vba-access/sagit-il-dun-jour-ferie">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Je vous présente une fonction écrite en VBA qui détermine si la date passée en argument correspond à un jour férié français ou non. La réponse est obtenue en moins d&rsquo;un millionième de seconde !<br />
<span id="more-560"></span><br />
<strong>Les jours fériés légaux en France</strong><br />
Ils sont au nombre de <strong>11</strong> dont 8 sont <strong>fixes </strong>(1er janvier, 1er mai, 8 mai, 14 juillet, 15 août, 1er novembre, 11 novembre et 25 décembre) et 3 <strong>mobiles </strong>(Lundi de Pâques, Jeudi de l&rsquo;Ascension et Lundi de Pentecôte).<br />
le Lundi de Pentecôte (<a href="http://travail-emploi.gouv.fr/informations-pratiques,89/fiches-pratiques,91/duree-du-travail,129/la-journee-de-solidarite,1021.html" title="Journée de solidarité" target="_blank">journée de solidarité</a>) est férié mais il peut être non chômé selon l&rsquo;entreprise. Un jour férié fixe n&rsquo;est pas non plus obligatoirement chômé puisqu&rsquo;il peut tomber un jour de week-end par exemple.</p>
<p><strong>La fonction en VBA</strong><br />
La fonction utilise la fonction <a href="http://blog.developpez.com/philben/p11431/vba-access/calculer-la-date-de-paques" title="Calculer la date de Pâques" target="_blank">Paques()</a> qui détermine la date du Dimanche de Pâques. Il faut donc que cette fonction soit présente dans le même projet ou module de code standard.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> EstJourFerie(<span style="color: #151B8D; font-weight: bold;">ByVal</span> laDate <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, <span style="color: #151B8D; font-weight: bold;">Optional</span> <span style="color: #151B8D; font-weight: bold;">ByVal</span> EstPentecoteFerie <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span> = <span style="color: #00C2FF; font-weight: bold;">True</span>) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span><br />
<span style="color: #008000;">'Détermine si la date passée en argument est un jour férié (en France) ou non :<br />
</span><span style="color: #008000;">' &nbsp; 101 = 1er Janvier - 501 = 1er Mai - 508 = 8 Mai - 714 = 14 Juillet<br />
</span><span style="color: #008000;">' &nbsp; 815 = 15 Août - 1101 = 1er Novembre - 1111 = 11 Novembre - 1225 = 25 Décembre<br />
</span><span style="color: #008000;">' &nbsp; dPa = Lundi de Pâques - dAs = Jeudi de l'Ascension - dPe = Lundi de Pentecôte<br />
</span><span style="color: #008000;">'Remarque : Le lundi de Pentecôte est un jour férié mais parfois non chômé (EstPentecoteFerie = False dans ce cas)<br />
</span><span style="color: #008000;">'Philben - v1.0 - 2012 - Free to use<br />
</span> &nbsp; <span style="color: #151B8D; font-weight: bold;">Static</span> Annee <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, dPa <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, dAs <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, dPe <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, bPe <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> a <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, m <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span><br />
<br />
&nbsp; &nbsp;a = Year(laDate): m = Month(laDate): j = Day(laDate)<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Select</span> <span style="color: #8D38C9; font-weight: bold;">Case</span> m * 100 + j<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Case</span> 101, 501, 508, 714, 815, 1101, 1111, 1225<br />
&nbsp; &nbsp; &nbsp; EstJourFerie = <span style="color: #00C2FF; font-weight: bold;">True</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Case</span> 323 <span style="color: #8D38C9; font-weight: bold;">To</span> 614 &nbsp; <span style="color: #008000;">'323: Date mini Lundi de Pâques - 614 : Date maxi Lundi de Pentecôte<br />
</span> &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> a &lt;&gt; Annee <span style="color: #8D38C9; font-weight: bold;">Or</span> EstPentecoteFerie &lt;&gt; bPe <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Annee = a: dPa = Paques(a) + 1: dAs = dPa + 38<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bPe = EstPentecoteFerie: <span style="color: #8D38C9; font-weight: bold;">If</span> bPe <span style="color: #8D38C9; font-weight: bold;">Then</span> dPe = dPa + 49 <span style="color: #8D38C9; font-weight: bold;">Else</span> dPe = #1/1/100#<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Select</span> <span style="color: #8D38C9; font-weight: bold;">Case</span> DateSerial(a, m, j): <span style="color: #8D38C9; font-weight: bold;">Case</span> dPa, dAs, dPe: EstJourFerie = <span style="color: #00C2FF; font-weight: bold;">True</span>: <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">Select</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">Select</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Explications</strong><br />
La fonction retourne Vrai si la date passée en argument correspond à un jour férié. Le deuxième argument optionnel permet de définir si le lundi de Pentecôte est réellement férié (non travaillé) ou non.<br />
On teste tout d&rsquo;abord la date par rapport aux jours fériés fixes. Ensuite, si elle ne correspond pas à l&rsquo;une de ces dates, on vérifie si elle est située dans la période théorique de l&rsquo;année des jours fériés mobiles entre la date du Lundi de Pâques (23 mars au plus tôt) et le lundi de Pentecôte (14 juin au plus tard) en sachant que l&rsquo;Ascension est comprise entre ces deux dates. Si c&rsquo;est le cas, on compare la date à ces 3 jours.<br />
La date de ces 3 jours mobiles est conservée dans une variable <strong>&lsquo;Static&rsquo;</strong> pour éviter un recalcul inutile si l&rsquo;année ne change pas entre deux appels et si le statut du lundi de Pentecôte n&rsquo;est pas modifié.</p>
<p><strong>Vérification des résultats</strong><br />
La fonction suivante contrôle notre fonction par rapport aux résultats de la <a href="http://access.developpez.com/faq/?page=dates#NbJourSsFeries" title="Comment savoir si un jour est ouvré ?" target="_blank">fonction EstFerie()</a> de la F.A.Q. qui est donc à télécharger.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TestResultatJourFerie()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> a <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, m <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, d <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, bErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Boolean</span><br />
<br />
&nbsp; &nbsp;<span style="color: #008000;">'Plage de EstFerie : 1982 à 2048<br />
</span> &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> a = 1982 <span style="color: #8D38C9; font-weight: bold;">To</span> 2048<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> m = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 12<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> j = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 31<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d = DateSerial(a, m, j)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">If</span> EstJourFerie(d) &lt;&gt; EstFerie(d) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bErr = <span style="color: #00C2FF; font-weight: bold;">True</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Date : &quot;</span> &amp; d; <span style="color: #800000;">&quot; - EstJourFerie() : &quot;</span> &amp; EstJourFerie(d) &amp; <span style="color: #800000;">&quot; - EstFerie() &quot;</span> &amp; EstFerie(d)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> m<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> a<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Fin TestResultatJourFerie() - &quot;</span> &amp; IIf(bErr, <span style="color: #800000;">&quot;Erreur(s) détectée(s)&quot;</span>, <span style="color: #800000;">&quot;Aucune erreur détectée&quot;</span>)<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Compléments à venir</strong><br />
Nous verrons dans des prochains billets comment utiliser cette fonction dans des cas plus spécifiques : S&rsquo;agit-il d&rsquo;un jour de week-end ou d&rsquo;un jour férié, s&rsquo;agit-il d&rsquo;un jour ouvré non travaillé,&#8230;</p>
<p>@+</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date du jour de semaine précédent</title>
		<link>https://blog.developpez.com/philben/p11454/vba-access/date-du-jour-de-semaine-precedent</link>
		<comments>https://blog.developpez.com/philben/p11454/vba-access/date-du-jour-de-semaine-precedent#comments</comments>
		<pubDate>Fri, 26 Oct 2012 03:40:25 +0000</pubDate>
		<dc:creator><![CDATA[philben]]></dc:creator>
				<category><![CDATA[VBA - Ms Access]]></category>
		<category><![CDATA[Algorithme]]></category>
		<category><![CDATA[Code VBA]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Jour de semaine]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philben/?p=551</guid>
		<description><![CDATA[Episode III de la saga &#8216;Weekday&#8217;. On souhaite obtenir cette fois-ci, la date d&#8217;un jour de semaine qui précède la date de référence. Préambule Je vous conseille de lire le premier billet de &#8216;Weekday&#8217; pour comprendre le principe des calculs. &#8230; <a href="https://blog.developpez.com/philben/p11454/vba-access/date-du-jour-de-semaine-precedent">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Episode <strong>III</strong> de la saga &lsquo;Weekday&rsquo;. On souhaite obtenir cette fois-ci, la date d&rsquo;un jour de semaine qui précède la date de référence.<br />
<span id="more-551"></span><br />
<strong>Préambule</strong><br />
Je vous conseille de lire le <a href="http://blog.developpez.com/philben/p11417/vba-access/date-du-jour-de-semaine-suivant" title="Date du jour de semaine suivant" target="_blank">premier billet de &lsquo;Weekday&rsquo;</a> pour comprendre le principe des calculs.<br />
Voir aussi le <a href="http://blog.developpez.com/philben/p12177/vba-access/vba-recapitulatif-des-fonctions-jour-de-semaine" title="VBA : Récapitulatif des fonctions ‘jour de semaine’" target="_blank">récapitulatif</a> des fonctions.</p>
<p><strong>Les matrices</strong><br />
On souhaite donc passer de la matrice &lsquo;Weekday&rsquo; à la matrice &lsquo;Jour précédent&rsquo;</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Weekday(Date,VbDayOfWeek) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Jour précédent &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VbDayOfWeek &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VbDayOfWeek &nbsp; &nbsp; &nbsp; <br />
Jour Date &nbsp; L &nbsp; M &nbsp; M &nbsp; J &nbsp; V &nbsp; S &nbsp; D &nbsp; &nbsp; &nbsp;Jour date &nbsp; L &nbsp; M &nbsp; M &nbsp; J &nbsp; V &nbsp; S &nbsp; D<br />
Lundi &nbsp; &nbsp; &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; &nbsp; &nbsp;Lundi &nbsp; &nbsp; &nbsp;-7 &nbsp;-6 &nbsp;-5 &nbsp;-4 &nbsp;-3 &nbsp;-2 &nbsp;-1<br />
Mardi &nbsp; &nbsp; &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; &nbsp; &nbsp;Mardi &nbsp; &nbsp; &nbsp;-1 &nbsp;-7 &nbsp;-6 &nbsp;-5 &nbsp;-4 &nbsp;-3 &nbsp;-2<br />
Mercredi &nbsp; &nbsp;3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; 4 vers Mercredi &nbsp; -2 &nbsp;-1 &nbsp;-7 &nbsp;-6 &nbsp;-5 &nbsp;-4 &nbsp;-3<br />
Jeudi &nbsp; &nbsp; &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; 5 &nbsp; &nbsp; &nbsp;Jeudi &nbsp; &nbsp; &nbsp;-3 &nbsp;-2 &nbsp;-1 &nbsp;-7 &nbsp;-6 &nbsp;-5 &nbsp;-4<br />
Vendredi &nbsp; &nbsp;5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; 6 &nbsp; &nbsp; &nbsp;Vendredi &nbsp; -4 &nbsp;-3 &nbsp;-2 &nbsp;-1 &nbsp;-7 &nbsp;-6 &nbsp;-5<br />
Samedi &nbsp; &nbsp; &nbsp;6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; 7 &nbsp; &nbsp; &nbsp;Samedi &nbsp; &nbsp; -5 &nbsp;-4 &nbsp;-3 &nbsp;-2 &nbsp;-1 &nbsp;-7 &nbsp;-6<br />
Dimanche &nbsp; &nbsp;7 &nbsp; 6 &nbsp; 5 &nbsp; 4 &nbsp; 3 &nbsp; 2 &nbsp; 1 &nbsp; &nbsp; &nbsp;Dimanche &nbsp; -6 &nbsp;-5 &nbsp;-4 &nbsp;-3 &nbsp;-2 &nbsp;-1 &nbsp;-7</div></div>
<p>&nbsp;<br />
On remarque que les lignes de la matrice &lsquo;Jour précédent&rsquo; correspondent aux lignes de la matrice &lsquo;Weekday&rsquo; avec un décalage de 1 jour.<br />
Par exemple, la ligne du lundi de &lsquo;Jour précédent&rsquo; est identique en valeur absolue à celle du dimanche de &lsquo;Weekday&rsquo;, celle du mardi est liée à lundi, etc&#8230;</p>
<p><strong>La solution</strong><br />
Il faut donc retrancher un jour à la date de référence avant de la passer à la fonction Weekday() : <code class="codecolorer vb blackboard"><span class="vb">Weekday(DateRef - 1, Jour)</span></code><br />
&nbsp;<br />
<strong>La fonction VBA</strong></p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> DateJourPrecedent(<span style="color: #151B8D; font-weight: bold;">ByVal</span> DateRef <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, <span style="color: #151B8D; font-weight: bold;">ByVal</span> Jour <span style="color: #151B8D; font-weight: bold;">As</span> VbDayOfWeek) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;DateJourPrecedent = DateRef - Weekday(DateRef - 1, Jour)<br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
<strong>Tester la fonction</strong><br />
La fonction suivante teste les 49 possibilités de la matrice et affiche les résultats dans la fenêtre ‘Exécution’ de l’éditeur VB.</p>
<div class="codecolorer-container vb blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> TestDateJourPrecedent()<br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> d <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, r <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span>, dates(1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7) <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Date</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> i <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, j <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, k <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span>, NbErr <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Integer</span><br />
&nbsp; &nbsp;<span style="color: #151B8D; font-weight: bold;">Dim</span> s <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">String</span>, Jours <span style="color: #151B8D; font-weight: bold;">As</span> <span style="color: #F660AB; font-weight: bold;">Variant</span><br />
<br />
&nbsp; &nbsp;d = Int(Now())<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">While</span> Weekday(d) &lt;&gt; vbMonday: d = d + 1: Wend<br />
&nbsp; &nbsp;Jours = VBA.Array(<span style="color: #800000;">&quot;Dimanche&quot;</span>, <span style="color: #800000;">&quot;Lundi &nbsp; &quot;</span>, <span style="color: #800000;">&quot;Mardi &nbsp; &quot;</span>, <span style="color: #800000;">&quot;Mercredi&quot;</span>, <span style="color: #800000;">&quot;Jeudi &nbsp; &quot;</span>, <span style="color: #800000;">&quot;Vendredi&quot;</span>, <span style="color: #800000;">&quot;Samedi &nbsp;&quot;</span>)<br />
<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;Test DateJourPrecedent()&quot;</span> &amp; vbCrLf &amp; <span style="color: #800000;">&quot;----------------------&quot;</span><br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">For</span> i = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7<br />
&nbsp; &nbsp; &nbsp; s = vbNullString<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;* Date de référence : &quot;</span> &amp; Format(d, <span style="color: #800000;">&quot;dddd dd/mm/yyyy&quot;</span>)<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> vbTab &amp; <span style="color: #800000;">&quot;Jour cherché&quot;</span> &amp; vbTab &amp; vbTab &amp; <span style="color: #800000;">&quot;Jour trouvé&quot;</span> &amp; vbTab &amp; vbTab &amp; <span style="color: #800000;">&quot;Conforme ?&quot;</span> &amp; vbCrLf &amp; _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vbTab &amp; <span style="color: #800000;">&quot;----------------------------------------------&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> k = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7: dates(Weekday(d - k)) = d - k: <span style="color: #8D38C9; font-weight: bold;">Next</span> k<br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">For</span> j = 1 <span style="color: #8D38C9; font-weight: bold;">To</span> 7<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;r = DateJourPrecedent(d, j)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s = s &amp; vbTab &amp; Jours(j - 1) &amp; vbTab &amp; vbTab &amp; Format(r, <span style="color: #800000;">&quot;ddd dd/mm/yyyy&quot;</span>) &amp; vbTab &amp; vbTab<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">If</span> r &lt;&gt; dates(j) <span style="color: #8D38C9; font-weight: bold;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NbErr = NbErr + 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s = s &amp; <span style="color: #800000;">&quot;Erreur !&quot;</span> &amp; vbCrLf<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s = s &amp; <span style="color: #800000;">&quot;Ok&quot;</span> &amp; vbCrLf<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #8D38C9; font-weight: bold;">Next</span> j<br />
&nbsp; &nbsp; &nbsp; Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> s<br />
&nbsp; &nbsp; &nbsp; d = d + 1<br />
&nbsp; &nbsp;<span style="color: #8D38C9; font-weight: bold;">Next</span> i<br />
&nbsp; &nbsp;Debug.<span style="color: #151B8D; font-weight: bold;">Print</span> <span style="color: #800000;">&quot;***&quot;</span> &amp; IIf(NbErr &gt; 0, NbErr, <span style="color: #800000;">&quot; Aucune&quot;</span>) &amp; <span style="color: #800000;">&quot; erreur(s) commise(s) ***&quot;</span><br />
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></div></div>
<p>&nbsp;<br />
@+ pour la suite des épisodes ‘Weekday’.</p>
<p>Philippe</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
