{"id":6134,"date":"2017-09-13T06:28:05","date_gmt":"2017-09-12T21:28:05","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=6134"},"modified":"2017-09-13T06:30:36","modified_gmt":"2017-09-12T21:30:36","slug":"adofilter","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/adofilter\/","title":{"rendered":"\u30ec\u30b3\u30fc\u30c9\u3092\u6307\u5b9a\u3057\u305f\u6761\u4ef6\u3067\u62bd\u51fa\u3059\u308b\uff08ADO\uff09Filter \u30d7\u30ed\u30d1\u30c6\u30a3"},"content":{"rendered":"<h2>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u6307\u5b9a\u3057\u305f\u6761\u4ef6\u3067\u62bd\u51fa\u3059\u308b<\/h2>\n<div class=\"m30-l\">\n<h3>Filter \u30d7\u30ed\u30d1\u30c6\u30a3<\/h3>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <em>object<\/em>.<strong>Filter<\/strong> = <em>Condition<\/em><\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h4>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>object&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5bfe\u8c61\u3068\u306a\u308b <span class=\"red\"><strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>Condition&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u62bd\u51fa\u3059\u308b\u6761\u4ef6\u5f0f\u3092\u6587\u5b57\u5217\u578b\uff08String\uff09\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002\u6761\u4ef6\u5f0f\u306f\u3001&#8221;\uff08\u4e8c\u91cd\u5f15\u7528\u7b26\uff09\u3067\u56f2\u307f\u307e\u3059\u3002<br \/>\n\t\u6761\u4ef6\u5f0f\u306f\u3001<strong><em>FieldName<\/em> <em>Operator<\/em> <em>Value<\/em><\/strong> \u3068\u3044\u3046\u5f62\u5f0f\u304b\u3089\u306a\u308b\u7bc0\u3067\u69cb\u6210\u3055\u308c\u307e\u3059\u3002<br \/>\n\t\u8907\u6570\u306e\u6761\u4ef6\u5f0f\u3092 <strong>And<\/strong> \u3084 <strong>Or<\/strong> \u3092\u4f7f\u3063\u3066\u9023\u7d50\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>FieldName \u30fb\u30fb\u30fb<strong>Recordset<\/strong> \u304b\u3089\u6709\u52b9\u306a\u5217\u540d\uff08\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\uff09\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\u306b\u7a7a\u767d\u6587\u5b57\u304c\u542b\u307e\u308c\u308b\u5834\u5408\u306f []\uff08\u89d2\u62ec\u5f27\uff09\u3067\u56f2\u3080\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/li>\n<li>Operator  \u30fb\u30fb\u30fb\u6bd4\u8f03\u6f14\u7b97\u5b50\uff08 >\u3001<\u3001<=\u3001\u304a\u3088\u3073 like \u6f14\u7b97\u5b50 \uff09\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>Value\u3000\u3000 \u30fb\u30fb\u30fb<em>FieldName<\/em> \u3068\u6bd4\u8f03\u3059\u308b\u5024\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u5024\u306b\u306f\u3001\u6587\u5b57\u5217\u3001\u6570\u5024\u3001\u65e5\u4ed8\u3092\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\u6587\u5b57\u5217\u306f\u3001\u2019\uff08\u5358\u4e00\u5f15\u7528\u7b26\uff09\u3067\u56f2\u307f\u307e\u3059\uff08user = &#8216;Rin&#8217;\uff09\u3002\u65e5\u4ed8\u306e\u5024\u306f\u3001#\uff08\u30b7\u30e3\u30fc\u30d7\u8a18\u53f7\uff09\u3067\u56f2\u307f\u307e\u3059\uff08sdate > #7\/22\/17#\uff09\u3002\u6570\u5024\u306e\u5834\u5408\u306f\u3001\u5c0f\u6570\u70b9\u3001\u6307\u6570\u8868\u8a18\u3092\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001like \u6f14\u7b97\u5b50\u306b\u306f\u3001\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9\u306b\u306f\u3001\u30a2\u30b9\u30bf\u30ea\u30b9\u30af\uff08*\uff09\u304a\u3088\u3073\u30d1\u30fc\u30bb\u30f3\u30c8\u8a18\u53f7\uff08%\uff09\u306e\u307f\u3067\u3001\u5fc5\u305a\u6587\u5b57\u5217\u306e\u672b\u5c3e\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u300ckeyword like &#8216;k*&#8217;\u300d\u3001\u300ckeyword like &#8216;*ba*&#8217;\u300d\u306e\u3088\u3046\u306b\u6587\u5b57\u5217\u306e\u672b\u5c3e\u307e\u305f\u306f\u6587\u5b57\u5217\u306e\u5148\u982d\u3068\u672b\u5c3e\u306b * \u3084 % \u3092\u4f7f\u7528\u3057\u3066\u691c\u7d22\u3057\u307e\u3059\u3002\u305f\u3060\u3057\u300ckeyword like &#8216;*ea&#8217;\u300d\u3001\u300ckeyword like &#8216;a*c&#8217;\u300d\u306e\u3088\u3046\u306b\u6587\u5b57\u5217\u306e\u5148\u982d\u3084\u6587\u5b57\u5217\u4e2d\u306b * \u3084 % \u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002\u3053\u306e\u5834\u5408\u306f\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002\u307e\u305f\u3001<em>Value<\/em> \u306b <strong>Null<\/strong> \u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002 <\/li>\n<\/ul>\n<\/li>\n<\/ul><\/div>\n<br \/>\n<p class=\"caution4\">Filter \u3092\u89e3\u9664\u3059\u308b\u306b\u306f\u3001<strong>Filter \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u306b\u3001\u5b9a\u6570 <strong>adFilterNone<\/strong>\uff080\uff09\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u3053\u308c\u306f\u3001Filter \u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u3001\u9577\u3055 0 \u306e\u6587\u5b57\u5217\uff08&#8221;&#8221;\uff09\u3092\u8a2d\u5b9a\u3057\u305f\u5834\u5408\u3068\u540c\u3058\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<br \/>\n    rs.Filter = <strong>adFilterNone<\/strong><br \/>\n    rs.Filter = &#8220;&#8221;<br \/>\n    \u203b rs \u306f\u3001Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\n  <\/p>\n<p class=\"caution4\"><strong>Filter \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u3092\u8a2d\u5b9a\u3059\u308b\u3068 <strong>Recordset<\/strong> \u5185\u306e\u30ec\u30b3\u30fc\u30c9\u3067\u3001\u30d5\u30a3\u30eb\u30bf\u51e6\u7406\u6e08\u307f\u306e\u30b5\u30d6\u30bb\u30c3\u30c8\u5185\u306e\u6700\u521d\u306e\u30ec\u30b3\u30fc\u30c9\u306b\u30ab\u30ec\u30f3\u30c8\u30ec\u30b3\u30fc\u30c9\u306e\u4f4d\u7f6e\u304c\u79fb\u52d5\u3057\u307e\u3059\u3002\u307e\u305f\u3001<strong>Filter \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u3092\u6d88\u53bb\u3059\u308b\u3068\u3001\u30ab\u30ec\u30f3\u30c8\u30ec\u30b3\u30fc\u30c9\u306e\u4f4d\u7f6e\u306f <strong>Recordset<\/strong> \u306e\u6700\u521d\u306e\u30ec\u30b3\u30fc\u30c9\u306b\u79fb\u52d5\u3057\u307e\u3059\u3002<\/p>\n<\/div>\n<br \/><br \/>\n<h2>Filter \u30d7\u30ed\u30d1\u30c6\u30a3 \u4f7f\u7528\u4f8b<\/h2>\n<div class=\"m30-l\">\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"Filter \u30d7\u30ed\u30d1\u30c6\u30a3\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_Filter()\r\n    \r\n    '\u53c2\u7167\u8a2d\u5b9a:Microsoft ActiveX Data Objects 6.1 Library\r\n    \r\n    Dim cn As ADODB.Connection\r\n    Dim rs As ADODB.Recordset\r\n    Dim constr As String\r\n    Dim DBFile As String\r\n    Dim i As Long\r\n    Dim j As Long\r\n    \r\n    DBFile = ActiveWorkbook.Path & \"\\mydb1.accdb\"\r\n    constr = \"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\" & DBFile\r\n    \r\n    Set cn = New ADODB.Connection\r\n    cn.ConnectionString = constr\r\n    cn.Open\r\n    \r\n    Set rs = New ADODB.Recordset\r\n    With rs\r\n        \r\n        '\u30c6\u30fc\u30d6\u30eb\u3092\u958b\u304f\r\n        .Source = \"\u30c6\u30fc\u30d6\u30eb3\"\r\n        .ActiveConnection = cn\r\n        .Filter = \"\u5e74\u5ea6 = 2009 AND \u6708\u5ea6 = 7 AND \u53d6\u5f15\u5148 like '%\u3231%'\"\r\n        .Open\r\n        \r\n    End With\r\n    \r\n    With Worksheets(\"Sheet1\")\r\n        rs.MoveFirst\r\n        i = 1\r\n        .Cells.Clear\r\n        Do Until rs.EOF\r\n            For j = 0 To rs.Fields.Count - 1\r\n                If i = 1 Then .Cells(i, j + 1) = rs(j).Name\r\n                .Cells(i + 1, j + 1) = rs(j).Value\r\n            Next j\r\n            rs.MoveNext\r\n            i = i + 1\r\n        Loop\r\n        .Columns(\"A:H\").AutoFit\r\n    End With\r\n    \r\n    rs.Close\r\n    Set rs = Nothing\r\n    \r\n    cn.Close\r\n    Set cn = Nothing\r\n    \r\nEnd Sub\r\n\u3000\r\n  <\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p><a href=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adofilter_01.jpg?ssl=1\" rel=\"lightbox[6134]\"><img loading=\"lazy\" src=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adofilter_01.jpg?resize=580%2C263&#038;ssl=1\" alt=\"Filter \u30d7\u30ed\u30d1\u30c6\u30a3\uff08ADO\uff09\" width=\"580\" height=\"263\" class=\"alignnone size-large wp-image-6138\" srcset=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adofilter_01.jpg?resize=580%2C263&amp;ssl=1 580w, https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adofilter_01.jpg?resize=400%2C182&amp;ssl=1 400w, https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adofilter_01.jpg?w=740&amp;ssl=1 740w\" sizes=\"(max-width: 580px) 100vw, 580px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<\/div>\n<br \/><br \/>\n","protected":false},"excerpt":{"rendered":"<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u6307\u5b9a\u3057\u305f\u6761\u4ef6\u3067\u62bd\u51fa\u3059\u308b Filter \u30d7\u30ed\u30d1\u30c6\u30a3 \u3010\u66f8\u5f0f &#8230; <\/p>\n","protected":false},"author":1,"featured_media":6138,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"amp_status":"","spay_email":"","jetpack_publicize_message":""},"categories":[948],"tags":[953,985,950,721,968,984,970,951,814,955,949,835],"jetpack_featured_media_url":"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adofilter_01.jpg?fit=740%2C336&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Ye9i-1AW","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6134"}],"collection":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/comments?post=6134"}],"version-history":[{"count":8,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6134\/revisions"}],"predecessor-version":[{"id":6334,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6134\/revisions\/6334"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/6138"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=6134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=6134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=6134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}