{"id":6140,"date":"2017-09-14T08:49:18","date_gmt":"2017-09-13T23:49:18","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=6140"},"modified":"2017-09-14T08:50:24","modified_gmt":"2017-09-13T23:50:24","slug":"adosort","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/adosort\/","title":{"rendered":"\u30ec\u30b3\u30fc\u30c9\u3092\u4e26\u3079\u66ff\u3048\u308b\uff08ADO\uff09Sort \u30d7\u30ed\u30d1\u30c6\u30a3"},"content":{"rendered":"<h2>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u4e26\u3079\u66ff\u3048\u308b<\/h2>\n<div class=\"m30-l\">\n<h3>Sort \u30d7\u30ed\u30d1\u30c6\u30a3<\/h3>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <em>object<\/em>.<strong>CursorLocation<\/strong> = <strong>adUseClient<\/strong><br \/>\n    <em>object<\/em>.<strong>Sort<\/strong> = &#8220;<em>FieldName<\/em> [ {<strong>ASC<\/strong> | <strong>DESC<\/strong>} ]&#8221;<\/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>FieldName&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5217\u540d\uff08\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\uff09\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>ASC,DESC&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u6607\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u306b\u306f <strong>ASC<\/strong>\u3001\u964d\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u306b\u306f <strong>DESC<\/strong> \u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u7701\u7565\u3059\u308b\u3068\u6607\u9806\u306b\u4e26\u3079\u66ff\u3048\u3089\u308c\u307e\u3059\u3002<\/li>\n<\/ul><\/div>\n<br \/>\n<p class=\"caution4\"><strong>Sort \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u3092\u4f7f\u7528\u3059\u308b\u306b\u306f\u3001<strong>CursorLocation \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u306b <strong>adUseClient<\/strong> \u3092\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p class=\"caution4\"><strong>Sort \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u306b\u7a7a\u6587\u5b57\u5217\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u3001\u884c\u306f\u5143\u306e\u9806\u5e8f\u306b\u30ea\u30bb\u30c3\u30c8\u3055\u308c\u3001\u4e00\u6642\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u524a\u9664\u3055\u308c\u307e\u3059\u3002\u65e2\u5b58\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f\u524a\u9664\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n<p class=\"caution4\">\u8907\u6570\u5217\u3092\u30bd\u30fc\u30c8\u3059\u308b\u5834\u5408\u3001,\uff08\u30ab\u30f3\u30de\uff09\u3067\u533a\u5207\u3063\u3066\u6307\u5b9a\u3057\u307e\u3059\u3002<br \/>\n    \u4f8b\uff1aRecordset\u300crs\u300d\u306b\u3001[firstCol]\u3001[middleCol]\u3001[lastCol] \u3068\u3044\u3046 3 \u3064\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u3042\u308b\u3068\u3059\u308b<br \/>\n    <strong>rs.Sort = &#8220;lastCol DESC, firstCol ASC&#8221;<\/strong><br \/>\n    \u3092\u8a2d\u5b9a\u3057\u305f\u5834\u5408\u3001Recordset \u306f\u3001\u307e\u305a\u300clastCol\u300d\u3092\u964d\u9806\u306b\u306b\u30bd\u30fc\u30c8\u3057\u3001\u6b21\u306b\u300cfirstCol\u300d\u3092\u6607\u9806\u306b\u30bd\u30fc\u30c8\u3057\u307e\u3059\u3002\u3053\u306e\u3068\u304d\u300cmiddleCol\u300d\u306f\u7121\u8996\u3057\u307e\u3059\u3002<\/p>\n<br \/><br \/>\n<h3>CursorLocation \u30d7\u30ed\u30d1\u30c6\u30a3<\/h3>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <em>object<\/em>.<strong>CursorLocation<\/strong> = <em>CursorLocationEnum<\/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>CursorLocationEnum&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30ab\u30fc\u30bd\u30eb\u30bf\u30a4\u30d7\u306e\u5834\u6240\u3092\u8868\u3059 <strong>CursorLocationEnum \u30af\u30e9\u30b9<\/strong> \u306e\u5b9a\u6570\u307e\u305f\u306f\u305d\u306e\u5024\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<strong>Sort \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong> \u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u3001\u5fc5\u305a <strong>adUseClient<\/strong> \u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<table>\n<tr>\n<td align = \"center\" width=\"200\" bgcolor=\"#ffffccc\"><strong>\u5b9a\u6570<\/strong><\/td>\n<td align = \"center\" width=\"50\" bgcolor=\"#ffffccc\"><strong>\u5024<\/strong><\/td>\n<td align = \"center\" width=\"400\" bgcolor=\"#ffffccc\"><strong>\u5185\u5bb9<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"200\">adUseNone<\/td>\n<td width=\"50\" align = \"center\">1<\/td>\n<td width=\"400\">\u30ab\u30fc\u30bd\u30eb\u30b5\u30fc\u30d3\u30b9\u3092\u4f7f\u3044\u307e\u305b\u3093\u3002<\/td>\n<\/tr>\n<tr>\n<td width=\"200\">adUseServer<\/td>\n<td width=\"50\" align = \"center\">2<\/td>\n<td width=\"400\">\u30b5\u30fc\u30d0\u30fc\u5074\u30ab\u30fc\u30bd\u30eb\uff08\u65e2\u5b9a\u5024\uff09<\/td>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"200\">adUseClient<\/td>\n<td width=\"50\" align = \"center\">3<\/td>\n<td width=\"400\">\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u30ab\u30fc\u30bd\u30eb<\/td>\n<\/tr>\n<\/table>\n<p>\n    <\/ul>\n<\/p><\/div>\n<br \/>\n<\/div>\n<br \/><br \/>\n<h2>Sort \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=\"Sort \u30d7\u30ed\u30d1\u30c6\u30a3\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_Sort()\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        .Source = \"\u30c6\u30fc\u30d6\u30eb3\"\r\n        .ActiveConnection = cn\r\n        .CursorLocation = adUseClient\r\n        .Sort = \"\u4ed5\u5165\u5148C desc, \u5e74\u5ea6 asc, \u6708\u5ea6 asc\"\r\n        .Filter = \"\u5e74\u5ea6 = 2009 AND \u4ed5\u5165\u5148C > 1300 AND \u4ed5\u5165\u5148C < 1600\"\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:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adosort_03.jpg?ssl=1\" rel=\"lightbox[6140]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adosort_03.jpg?resize=580%2C354&#038;ssl=1\" alt=\"Sort \u30d7\u30ed\u30d1\u30c6\u30a3\uff08ADO\uff09\" width=\"580\" height=\"354\" class=\"alignnone size-large wp-image-6144\" srcset=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adosort_03.jpg?resize=580%2C354&amp;ssl=1 580w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adosort_03.jpg?resize=400%2C244&amp;ssl=1 400w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adosort_03.jpg?w=696&amp;ssl=1 696w\" 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\u4e26\u3079\u66ff\u3048\u308b Sort \u30d7\u30ed\u30d1\u30c6\u30a3 \u3010\u66f8\u5f0f\u3011 object &#8230; <\/p>\n","protected":false},"author":1,"featured_media":6144,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"amp_status":"","spay_email":"","jetpack_publicize_message":""},"categories":[948],"tags":[953,950,988,721,987,968,970,986,951,814,955,949,835],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adosort_03.jpg?fit=696%2C425&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s4Ye9i-adosort","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6140"}],"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=6140"}],"version-history":[{"count":6,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6140\/revisions"}],"predecessor-version":[{"id":6361,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6140\/revisions\/6361"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/6144"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=6140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=6140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=6140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}