Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-窗体/数据页

【access小品】黑箱---程序开发的一种机巧思路

时 间:2010-07-12 00:00:00
作 者:todaynew   ID:10802  城市:武汉
摘 要:黑箱
正 文:

  昨日,版友子煜同志上传了一个关于追加查询问题的实例,读出数据和写入数据的两个表字段多,字段名复杂,加之还存在一些逻辑上的矛盾。因此直接写追加查询很是麻烦,用ADO数据集解决也很罗嗦。于是乎,需要另辟蹊径,超常规解决问题。通过观察发现,所需追加的来源和被追加的目标在窗体上反映的是很清晰的,这就提供了一个解决问题的基本思路,叫做“从窗体中来到窗体中去”,窗体背后是些什么玩意完全可以不必考虑。这也就是一种被称之为黑箱管理的思维方法。实际上Access设计中,常常需要这样去建立解决问题的思路,这个思路可以导致许多通用程序的构建。

Private Sub Command4_Click()
Dim frm1 As Form
Dim ctls1 As Controls
Dim ctl1 As Control
Dim frm2 As Form
Dim ctls2 As Controls
Dim i As Long, j As Long
Set frm1 = Me.条件查询入库明细子窗体.Form
Set ctls1 = frm1.Controls
Set frm2 = Forms("出库主窗体").Controls("F_ProIn2").Form
Set ctls2 = frm2.Controls
For i = 1 To frm1.RecordsetClone.RecordCount
           frm1.SelTop = i
           If ctls1("P_Select") = True Then
                Forms("出库主窗体").Form.SetFocus
                Forms("出库主窗体").Controls("F_ProIn2").SetFocus
                If Nz(ctls2("P_ID").Value, 0) <> 0 Then
                       DoCmd.RunCommand acCmdRecordsGoToNew
                End If
                For Each ctl1 In ctls1
                       If ctl1.ControlType <> acLabel Then
                              If ctlEx(frm2, ctl1.Name) = True Then
                                     ctls2(ctl1.Name).Value = ctl1.Value
                              End If
                       End If
                  Next ctl1
           End If
Next
frm1.Requery
frm2.Requery
End Sub

Function ctlEx(frm As Form, ctlname As String) As Boolean
Dim ctls As Controls
Dim ctl As Control
Set ctls = frm.Controls
ctlEx = False
For Each ctl In ctls
       If ctl.Name = ctlname Then
            ctlEx = True
            Exit For
       End If
Next ctl
End Function

点击下载此附件




Access软件网QQ交流群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助