{"id":6126,"date":"2017-09-12T07:51:50","date_gmt":"2017-09-11T22:51:50","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=6126"},"modified":"2017-09-12T07:51:50","modified_gmt":"2017-09-11T22:51:50","slug":"adodelete","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/adodelete\/","title":{"rendered":"\u30ec\u30b3\u30fc\u30c9\u306e\u524a\u9664\uff08ADO\uff09Delete \u30e1\u30bd\u30c3\u30c9"},"content":{"rendered":"<h2>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u524a\u9664\u3059\u308b<\/h2>\n<div class=\"m30-l\">\n<h3>Delete \u30e1\u30bd\u30c3\u30c9<\/h3>\n<p>\u30ab\u30ec\u30f3\u30c8\u30ec\u30b3\u30fc\u30c9\u3092\u524a\u9664\u3057\u307e\u3059\u3002<\/p>\n<div class=\"kkbox\"><strong>\u3010\u66f8\u5f0f\u3011<\/strong><\/p>\n<p>    <em>object<\/em>.<strong>Delete<\/strong><\/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<\/ul><\/div>\n<br \/>\n<p class=\"caution4\">\u30ec\u30b3\u30fc\u30c9\u3092\u524a\u9664\u3059\u308b\u5834\u5408\u3001<strong>Recordset \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u306eOpen \u30e1\u30bd\u30c3\u30c9\u306e\u5f15\u6570 <strong>LockType<\/strong> \u306b\u306f\u3001<strong>adLockOptimistic<\/strong> \u307e\u305f\u306f <strong>adLockPessimistic<\/strong> \u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\uff08<strong>Recordset<\/strong> \u3092\u958b\u304f\u6642\u306b\u4f7f\u3046\u30ed\u30c3\u30af\u306e\u7a2e\u985e\u306b\u95a2\u3057\u3066\u306f\u3001<a href=\"https:\/\/excelwork.info\/excel\/databaseadobase\/\">\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff08Access \u7b49\uff09\u306b\u63a5\u7d9a\uff08ADO\uff09<\/a> \u3092\u53c2\u7167\u3057\u3066\u4e0b\u3055\u3044\u3002\uff09<\/p>\n<p class=\"caution4\">\u30ab\u30ec\u30f3\u30c8\u30ec\u30b3\u30fc\u30c9\u306f\u3001\u30ec\u30b3\u30fc\u30c9\u524a\u9664\u5f8c\u3082\u300c\u524a\u9664\u3055\u308c\u305f\u30ec\u30b3\u30fc\u30c9\u300d\u3068\u3057\u3066\u5b58\u5728\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u306e\u72b6\u614b\u3067\u3001\u30ab\u30ec\u30f3\u30c8\u30ec\u30b3\u30fc\u30c9\u306b\u5bfe\u3057\u3066\u51e6\u7406\u3092\u884c\u3046\u3068\u3001\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002\uff08 <strong>MoveNext \u30e1\u30bd\u30c3\u30c9<\/strong> \u7b49\u3092\u4f7f\u3063\u3066\u30ab\u30fc\u30bd\u30eb\u3092\u79fb\u52d5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\uff09<\/p>\n<\/div>\n<br \/><br \/>\n<h2>Delete \u30e1\u30bd\u30c3\u30c9 \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=\"Delete \u30e1\u30bd\u30c3\u30c9\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_Delete()\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\u30eb1\"\r\n        .ActiveConnection = cn\r\n        .CursorType = adOpenKeyset      '\u30ad\u30fc\u30bb\u30c3\u30c8\u30ab\u30fc\u30bd\u30eb\u4f7f\u7528\r\n        .LockType = adLockPessimistic   '\u30ec\u30b3\u30fc\u30c9\u5358\u4f4d\u6392\u4ed6\u7684\u30ed\u30c3\u30af\r\n        .Open\r\n        \r\n        'ID=1 \u306e\u30ec\u30b3\u30fc\u30c9\u306b\u30ab\u30fc\u30bd\u30eb\u3092\u79fb\u52d5\r\n        .Find \"ID = 1\", 0, adSearchForward\r\n        \r\n        '\u30ab\u30ec\u30f3\u30c8\u30ec\u30b3\u30fc\u30c9\u3092\u524a\u9664\r\n        .Delete\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    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\/adodelete_01.jpg?ssl=1\" rel=\"lightbox[6126]\"><img loading=\"lazy\" src=\"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adodelete_01.jpg?resize=376%2C246&#038;ssl=1\" alt=\"Delete \u30e1\u30bd\u30c3\u30c9\uff08ADO\uff09\" width=\"376\" height=\"246\" class=\"alignnone size-full wp-image-6130\" 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\u524a\u9664\u3059\u308b Delete \u30e1\u30bd\u30c3\u30c9 \u30ab\u30ec\u30f3\u30c8\u30ec\u30b3\u30fc\u30c9\u3092\u524a\u9664 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":6130,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"amp_status":"","spay_email":"","jetpack_publicize_message":""},"categories":[948],"tags":[953,950,721,318,968,970,951,814,955,949,835],"jetpack_featured_media_url":"https:\/\/i2.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/08\/adodelete_01.jpg?fit=376%2C246&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Ye9i-1AO","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6126"}],"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=6126"}],"version-history":[{"count":5,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6126\/revisions"}],"predecessor-version":[{"id":6325,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6126\/revisions\/6325"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/6130"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=6126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=6126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=6126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}