{"id":6051,"date":"2017-08-28T08:41:22","date_gmt":"2017-08-27T23:41:22","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=6051"},"modified":"2017-08-28T08:41:22","modified_gmt":"2017-08-27T23:41:22","slug":"adocopyfromrecordset","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/adocopyfromrecordset\/","title":{"rendered":"Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5185\u5bb9\u3092\u30ef\u30fc\u30af\u30b7\u30fc\u30c8\u306b\u30b3\u30d4\u30fc\u3059\u308b\uff08CopyFromRecordset \u30e1\u30bd\u30c3\u30c9\u30fbADO\uff09"},"content":{"rendered":"<h2>CopyFromRecordset \u30e1\u30bd\u30c3\u30c9<\/h2>\n<div class=\"m30-l\">\n<p>ADO \u306e <strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u5168\u3066\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u30ef\u30fc\u30af\u30b7\u30fc\u30c8\u306b\u30b3\u30d4\u30fc\u3057\u307e\u3059\u3002\u6307\u5b9a\u3055\u308c\u305f\u30bb\u30eb\u7bc4\u56f2\u306e\u5de6\u4e0a\u7aef\u3092\u8d77\u70b9\u3068\u3057\u3066\u3001\u30c7\u30fc\u30bf\u3092\u8cbc\u308a\u4ed8\u3051\u307e\u3059\u3002<\/p>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <em>RecordCount<\/em> = <em>object<\/em>.<strong>CopyFromRecordset<\/strong> ( <em>Data<\/em>, <em>MaxRows<\/em>, <em>MaxColumns<\/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>Range \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/li>\n<li>Data&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30b3\u30d4\u30fc\u3059\u308b <strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong> \u3092\u6307\u5b9a\u3057\u307e\u3059\uff08\u7701\u7565\u4e0d\u53ef\uff09\u3002<\/li>\n<li>MaxRows&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30b3\u30d4\u30fc\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u306e\u6700\u5927\u6570\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u7701\u7565\u3057\u305f\u5834\u5408\u3001<strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u306e\u3059\u3079\u3066\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3057\u307e\u3059\u3002<\/li>\n<li>MaxColumns&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30b3\u30d4\u30fc\u3059\u308b\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u6700\u5927\u6570\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u7701\u7565\u3057\u305f\u5834\u5408\u3001<strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u306e\u3059\u3079\u3066\u306e\u30d5\u30a3\u30a4\u30fc\u30eb\u30c9\u3092\u30b3\u30d4\u30fc\u3057\u307e\u3059\u3002<\/li>\n<li>RecordCount&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u30b3\u30d4\u30fc\u3057\u305f\u30ec\u30b3\u30fc\u30c9\u6570\u3002<\/li>\n<\/ul>\n<br \/>\n<p class=\"caution4\">\u30b3\u30d4\u30fc\u306f <strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u306e\u30ab\u30ec\u30f3\u30c8\u30ec\u30b3\u30fc\u30c9\u306e\u4f4d\u7f6e\u304b\u3089\u884c\u308f\u308c\u307e\u3059\u3002\u30b3\u30d4\u30fc\u304c\u5b8c\u4e86\u3059\u308b\u3068\u3001<strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u306e <strong>EOF \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong>\u306f <strong>True<\/strong> \u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<\/p><\/div>\n<\/div>\n<br \/><br \/>\n<h2>CopyFromRecordset \u30e1\u30bd\u30c3\u30c9\u306e\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=\"CopyFromRecordset \u30e1\u30bd\u30c3\u30c9\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_ADO_CopyFromRecordset()\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 strSQL As String\r\n    Dim num 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    strSQL = \"Select * from \u793e\u54e1\u540d\u7c3f where ID < 10 order by ID;\"\r\n    \r\n    Set Rs = New ADODB.Recordset\r\n    Rs.Source = strSQL\r\n    Rs.ActiveConnection = cn\r\n    Rs.Open\r\n    \r\n    With Worksheets(\"Sheet1\")\r\n    \r\n        .Cells.Clear\r\n        num = .Range(\"A1\").CopyFromRecordset(Data:=Rs)\r\n        .Cells(.Rows.Count, \"A\").End(xlUp).Offset(2, 0).Value = \"\u30ec\u30b3\u30fc\u30c9\u6570\"\r\n        .Cells(.Rows.Count, \"A\").End(xlUp).Offset(0, 1).Value = num\r\n    \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:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/adocopyfromrecordset_01.jpg?ssl=1\" rel=\"lightbox[6051]\"><img loading=\"lazy\" src=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/adocopyfromrecordset_01.jpg?resize=555%2C335&#038;ssl=1\" alt=\"CopyFromRecordset \u30e1\u30bd\u30c3\u30c9\" width=\"555\" height=\"335\" class=\"alignnone size-full wp-image-6053\" srcset=\"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/adocopyfromrecordset_01.jpg?w=555&amp;ssl=1 555w, https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/adocopyfromrecordset_01.jpg?resize=400%2C241&amp;ssl=1 400w\" sizes=\"(max-width: 555px) 100vw, 555px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>CopyFromRecordset \u30e1\u30bd\u30c3\u30c9 ADO \u306e Recordset \u30aa &#8230; <\/p>\n","protected":false},"author":1,"featured_media":6053,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"amp_status":"","spay_email":"","jetpack_publicize_message":""},"categories":[948],"tags":[950,886,966,967,954,672,951,814,955,949],"jetpack_featured_media_url":"https:\/\/i1.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/adocopyfromrecordset_01.jpg?fit=555%2C335&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Ye9i-1zB","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6051"}],"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=6051"}],"version-history":[{"count":4,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6051\/revisions"}],"predecessor-version":[{"id":6207,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6051\/revisions\/6207"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/6053"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=6051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=6051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=6051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}