screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('/uploads/allimg/101019/13135R5D-0.jpg');}" src="/upload/old/allimg/101019/13135R5D-0.jpg" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0> 图 1
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" style="CURSOR: hand" onclick="if(!this.resized) {return true;} else {window.open('/uploads/allimg/101019/13135S516-1.jpg');}" alt="" src="/upload/old/allimg/101019/13135S516-1.jpg" width=716 onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0 resized="true" pop="Click here to open new window
CTRL+Mouse wheel to zoom in/out"> 图 2
菜单项调用自定义函数需要两个步骤。您需要创建一个菜单项,然后为它的 On Action 属性分配自定义函数。创建菜单的第一步看起来可能不太直观:我根据自定义菜单对话框改写了一个现有的命令。我经常将一个虚拟宏拖到菜单栏上,然后根据需要更改它的名称和按钮图像。
创建菜单之后,分配函数就很简单了。我只需用函数的名称重写任何现有的 On Action 菜单项,并在前面添加一个等号。On Action 项有三个特征:它必须是一个函数而非子例程,该函数不能返回值,并且其中必须包含括号。以下就是我用来打开排序对话框的项:
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('/uploads/allimg/101019/13135TC0-2.jpg');}" src="/upload/old/allimg/101019/13135TC0-2.jpg" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0> 图 3
以下是这段代码,开头是模块级的变量,用于在模块的例程间传递信息。对话框的 Open 事件中有一段关键的代码,它删除了表格中的所有记录。然后,代码循环访问组成窗体记录集的所有字段(我通过窗体的 RecordsetClone 属性检索窗体的记录集)。但是,仅仅因为字段出现在记录集中,并不意味着字段实际上在窗体中显示。因此,代码随后循环访问调用窗体上的控件,如果控件正在使用 RecordsetClone 中的一个字段,并且该字段可见,那么代码会将该字段添加到表格,并进行标记以备 lstFields 列表框使用:
Dim frm As Form 'the calling form or subform Dim rst As Recordset 'recordsource for the listboxes Dim iSortOrder As Integer
Private Sub Form_Open(Cancel As Integer) On Error GoTo ErrorHandler Dim fld As Field, ctl As Control, obj As Object
Set obj = Screen.ActiveControl.Parent Do Until HasProperty(obj, "HasModule") Set obj = obj.Parent Loop
Set frm = obj CurrentDb.Execute _ "DELETE FROM zstblMultiFieldSorting", dbFailOnError Set rst = CurrentDb.OpenRecordset( _ "zstblMultiFieldSorting", dbOpenDynaset) For Each fld In frm.RecordsetClone.Fields For Each ctl In frm If HasProperty(ctl, "controlsource") Then If ctl.ControlSource = fld.Name Then If ctl.Visible Then rst.AddNew rst!ListName = "lstFields" rst!FldName = fld.Name rst.Update End If End If End If Next ctl Next fld lstFields.Requery lstSort.Requery
If lstFields.ItemsSelected.Count Then With rst .FindFirst "FldName='" & lstFields.Value & "'" If Not .NoMatch Then iSortOrder = iSortOrder + 1 .Edit !ListName = "lstSort" !AscDesc = AscDesc() !SortOrder = iSortOrder .Update End If End With End If lstFields.Requery lstSort.Requery
End Sub
Private Sub cmdAddAll_Click() Dim fContinue As Boolean
fContinue = True With rst .MoveFirst Do While fContinue .FindFirst "ListName='" & "lstFields" & "'" If Not .NoMatch Then .Edit iSortOrder = iSortOrder + 1 !ListName = "lstSort" !AscDesc = AscDesc() !SortOrder = iSortOrder .Update Else fContinue = False End If Loop End With lstFields.Requery lstSort.Requery
End Sub
Private Sub cmdRemove_Click()
If lstSort.ItemsSelected.Count Then With rst .FindFirst "FldName='" & lstSort.Value & "'" If Not .NoMatch Then .Edit !ListName = "lstFields" !AscDesc = Null !SortOrder = Null .Update End If End With End If lstFields.Requery lstSort.Requery
End Sub
Private Sub cmdRemoveAll_Click()
With rst .MoveFirst Do While Not .EOF .Edit !ListName = "lstFields" !AscDesc = Null !SortOrder = Null .Update .MoveNext Loop End With lstFields.Requery lstSort.Requery iSortOrder = 0
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('/uploads/allimg/101019/13135T523-3.jpg');}" src="/upload/old/allimg/101019/13135T523-3.jpg" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0>
Private Sub cmdApply_Click() Dim strOrderBy As String, rstSorted As Recordset
rst.Sort = "SortOrder" Set rstSorted = rst.OpenRecordset With rstSorted .MoveFirst Do While Not .EOF If !ListName = "lstSort" Then strOrderBy = strOrderBy & !FldName & " " _ & !AscDesc & ", " End If .MoveNext Loop End With If Len(strOrderBy) Then strOrderBy = Left(strOrderBy, Len(strOrderBy) - 2) frm.OrderBy = strOrderBy frm.OrderByOn = True End If
Exit_Here: rstSorted.Close DoCmd.Close acForm, Me.Name Exit Sub