access複製父窗體和子窗體的選擇的記録
- 2019-09-05 15:14:00
- tmtony8 原創
- 3691
在應用程序中,我們有時需要複製父子窗體選中的記録
比如複製訂單記録。包括訂單信息,訂單明細信息,詳細代碼如下:
Dim strSql As String 'SQL statement. Dim lngID As Long 'Primary key value of the new record. 'Save any edits first If Me.Dirty Then Me.Dirty = False End If 'Make sure there is a record to duplicate. If Me.NewRecord Then MsgBox "Select the record to duplicate." Else 'Duplicate the main record: add to form's clone. With Me.RecordsetClone .AddNew !訂單id = Me.訂單id !客戶 = Me.客戶 !髮貨日期 = Me.髮貨日期 'etc for other fields. .Update 'Save the primary key value, to use as the foreign key for the related records. .Bookmark = .LastModified lngID = !ID 'Duplicate the related records: append query. If Me.subform.Form.RecordsetClone.RecordCount > 0 Then strSql = "INSERT INTO 訂單明細 ( 訂單id, 訂單明細id, 數量, 商品, 單價 ) " & _ "SELECT 訂單id, 訂單明細id, 數量, 商品, 單價 " & _ "FROM 訂單明細 WHERE 訂單id = " & ID & "" DBEngine(0)(0).Execute strSql, dbFailOnError Else MsgBox "Main record duplicated, but there were no related records." End If 'Display the new duplicate. Me.Bookmark = .LastModified End With End If Exit_Handler: Exit Sub Err_Handler: MsgBox "Error " & Err.Number & " - " & Err.Description, , "cmdDupe_Click" Resume Exit_Handler
此時訂單和訂單明細中都能複製添加上記録
Access數據庫自身
- office課程播放地址及課程明細
- Excel Word PPT Access VBA等Office技巧學習平颱
- 將( .accdb) 文件格式數據庫轉換爲早期版本(.mdb)的文件格式
- 將早期的數據庫文件格式(.mdb)轉換爲 (.accdb) 文件格式
- KB5002984:配置 Jet Red Database Engine 數據庫引擎和訪問連接引擎以阻止對遠程數據庫的訪問(remote table)
- Access 365 /Access 2019 數據庫中哪些函數功能和屬性被沙箱模式阻止(如未啟動宏時)
- Access Runtime(運行時)最全的下載(2007 2010 2013 2016 2019 Access 365)
文章分類
聯繫我們
聯繫人: | 王先生 |
---|---|
Email: | 18449932@qq.com |
QQ: | 18449932 |
微博: | officecn01 |