Office中国论坛/Access中国论坛

标题: 这段代码如何做成公用模块? [打印本页]

作者: cnhbjm    时间: 2005-11-9 00:19
标题: 这段代码如何做成公用模块?
Dim ctl As Control

    For Each ctl In Me.Controls

        Select Case ctl.ControlType

        Case acTextBox    '是文本框,要清空(锁定的文本框不能赋值)

          If ctl.Locked = False Then ctl.Value = Null

        

        Case acComboBox    '是组合框,也要清空

            ctl.Value = Null

            '其它类型的控件不处理

        End Select

    Next

由于有me. 不知道怎么做成公用模块,高手赐教。
作者: gaoqiwen    时间: 2005-11-9 00:54
试试:Public Function Cl(Conts As Controls)    Dim ctl As Control

    For Each ctl In Conts

        Select Case ctl.ControlType

        Case acTextBox

          If ctl.Locked = False Then ctl.Value = Null

        Case acComboBox

            ctl.Value = Null

        End Select

    NextEnd Function

调用:Cl Me.Controls
作者: cnhbjm    时间: 2005-11-9 18:58
谢!
作者: Dragxixi    时间: 2005-11-9 21:33
学习
作者: toby0988    时间: 2006-6-27 01:43


这段代码又如何做成公用模块?谢谢。(出自“报表.MDB)



Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Dim CtlDetail As Control
Dim intLineMargin As Integer

intLineMargin = 60

For Each CtlDetail In Me.Section(acDetail).Controls
    With CtlDetail
        If CtlDetail.Name <> "Memo" Then
        Me.Line ((.Left + .Width + intLineMargin), 1)-(.Left + .Width + _
intLineMargin, Me.Height)
        End If
    End With
Next
   

    With Me
        Me.Line (1, 1)-Step(.Width, .Height), 1, B
    End With

Set CtlDetail = Nothing

End Sub
作者: fan0217    时间: 2006-6-27 02:16
关键是方法,这样的同类问题就需要你自己动手来解决了。
作者: toby0988    时间: 2006-6-27 17:12
已成功,调用:Cl Me.Report

可在报表主体及页眉调用。

Public Sub C1(C11 As Report)

Dim CtlDetail As Control
Dim intLineMargin As Integer
intLineMargin = 60
For Each CtlDetail In C11.Section(0).Controls  

    With CtlDetail
         If CtlDetail.Name <> "Memo" Then
             C11.Line ((.Left + .Width + intLineMargin), 1)-(.Left + .Width + intLineMargin, C11.Height)
        End If
    End With
Next
    With C11
        C11.Line (1, 1)-Step(.Width, .Height), 1, B
    End With
Set CtlDetail = Nothing


End Sub




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3