设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1443|回复: 5
打印 上一主题 下一主题

[模块/函数] 国外看到的有关多窗体的用法(使用集合Collection,做成了类)有部分代码可参考一下

[复制链接]

点击这里给我发消息

跳转到指定楼层
1#
发表于 2015-6-6 08:20:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
国外看到的有关多窗体的用法(使用集合Collection,做成了类)有部分代码可参考一下,能看懂的自己去琢磨一下
"clsMultipleFormManager"
Option Compare Database
Option Explicit
Public clnOpenSubForms As New Collection
Private frmMainForm As Form
Private strDefaultDispatcherName As String  ' Keeps the name to prevent having to re-enter it on every form
Private blnLogSheetOpen As Boolean
Private lstOpenSubForms As ListBox
Private blnOpenSubFormsAssigned As Boolean
Private chldSubFormContainer As SubForm
Private blnSubFormContainerAssigned As Boolean
Enum SubFormSortOrder
    AllLogEntries
    LogEntry
    RequestForService
End Enum
Public Sub OpenNewForm(UseLogForm As LogEntryFormTypes)
Dim NewForm As Form
Dim obj As AccessObject, dbs As Object
Dim CurrentSubFormSortOrderValue As SubFormSortOrder
Dim SubFormName As String
Set dbs = Application.CurrentProject
Select Case UseLogForm
    Case LogSheet ' Open only one copy of the Log sheet
        If blnLogSheetOpen = False Then
            Set NewForm = New Form_frmLog_Entry_Details
            CurrentSubFormSortOrderValue = AllLogEntries
            SubFormName = """Log Entries"""
            blnLogSheetOpen = True
        Else
            Exit Sub
        End If
        
    Case GeneralLogEntry
        Set NewForm = New Form_sfrmEntryForm
        With NewForm
            .AllowAdditions = True
            .AllowEdits = True
            .DataEntry = True
            .Filter = "Entry_Number=-1"
            .FilterOn = True
'            .Name = .Name & " " & CStr(CDbl(Now()))
        End With
        SubFormName = Chr$(34) & Left(NewForm.DerivedFormName(), OpenSubFormTempNameMaxLength) & _
                      Chr$(34)
        CurrentSubFormSortOrderValue = LogEntry
        
    Case RequestForService
        Set NewForm = New Form_frmRequisition
        CurrentSubFormSortOrderValue = RequestForService
               
End Select
'NewForm.Visible = False
clnOpenSubForms.Add Item:=NewForm, Key:=CStr(NewForm.Hwnd)
' Put the new form's Hwnd into the Open Subform table so it will be
' available in the listbox
CurrentDb.Execute "INSERT INTO tblOpenSubForms ( SubFormhWnd, SubFormName, SortOrder, GeneratedName ) " & _
                  "SELECT " & NewForm.Hwnd & ", " & _
                  SubFormName & ", " & CurrentSubFormSortOrderValue & ", '" & _
                  NewForm.Name & "';"
' Requery the Open Subform listbox to being it up to date
PopulateListBox
' Manually set the listbox to the newly opened form and then run
' the activation routine
lstOpenSubForms = CStr(NewForm.Hwnd)
Call ActivateSubForm
Set NewForm = Nothing
End Sub
Public Sub ActivateSubForm()
Dim TempForm As Form
' First make any current form in the subform container invisible, then switch in
' the new form and make it visible
'    For Each TempForm In clnOpenSubForms
'        TempForm.Visible = False
'    Next TempForm
'    clnOpenSubForms(lstOpenSubForms).Visible = True
    chldSubFormContainer.SourceObject = clnOpenSubForms(lstOpenSubForms).Name
'    chldSubFormContainer.SourceObject = clnOpenSubForms(lstOpenSubForms)
Form_frmSubFormShell.chldOpenSubForms.Requery
End Sub
Private Sub PopulateListBox()
lstOpenSubForms.Requery
End Sub
Public Sub CloseSubForm()
Dim TempForm As Form
' Calling this routine should only be done after the subform has saved its current record
Set TempForm = clnOpenSubForms(lstOpenSubForms)
' Remove the subform from the collection, remove the reference from the Open Subform
' table, requery the Open Subform listbox, then choose the Log sheet to be
' displayed again
clnOpenSubForms.Remove (lstOpenSubForms)
CurrentDb.Execute "DELETE tblOpenSubForms.SubFormhWnd " & _
                  "FROM tblOpenSubForms " & _
                  "WHERE tblOpenSubForms.SubFormhWnd='" & lstOpenSubForms & "';"
PopulateListBox
lstOpenSubForms = DLookup("SubFormhWnd", "tblOpenSubForms", "SubFormName=""Log Entries""")
ActivateSubForm
End Sub
Public Sub RefreshActiveSubform()
If lstOpenSubForms = DLookup("SubFormhWnd", "tblOpenSubForms", "SubFormName=""Log Entries""") Then
    chldSubFormContainer.Form.Requery
End If
End Sub
Property Get MainForm() As Form
    Set MainForm = frmMainForm
End Property
Property Let MainForm(MainFormName As Form)
    Set frmMainForm = MainFormName
End Property
Property Let OpenSubFormsListBox(ListBoxArg As ListBox)
    Set lstOpenSubForms = ListBoxArg
    blnOpenSubFormsAssigned = True
End Property
Property Get OpenSubFormsListBox() As ListBox
    Set OpenSubFormsListBox = lstOpenSubForms
End Property
Property Let SubFormContainer(SubFormArg As SubForm)
    Set chldSubFormContainer = SubFormArg
    blnSubFormContainerAssigned = True
End Property
Property Get SubFormContainer() As SubForm
    Set SubFormContainer = chldSubFormContainer
End Property
Private Sub Class_Initialize()
blnLogSheetOpen = False
blnOpenSubFormsAssigned = False
blnSubFormContainerAssigned = False
' If this form has been shut down properly the prior time it was used,
' the Open Subform table should be empty, but clear it out anyway just to be safe
CurrentDb.Execute "DELETE tblOpenSubForms.SubFormhWnd " & _
                  "FROM tblOpenSubForms;"
End Sub

评分

参与人数 1经验 +10 收起 理由
zpy2 + 10 锛堝叾瀹冿級浼樼鏁欑▼銆佸師鍒涘唴瀹广.

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享分享 分享淘帖 订阅订阅

点击这里给我发消息

2#
发表于 2015-6-6 14:25:14 | 只看该作者
{:soso_e177:}

点击这里给我发消息

3#
发表于 2015-6-7 04:55:03 来自手机 | 只看该作者
http://answers.microsoft.com/en-us/office/forum/office_2007-access/setting-a-subforms-sourceobject-to-a-member-of-a/d9617b6c-f716-4474-a172-4f53fd15aac7

点击这里给我发消息

4#
发表于 2015-6-7 04:56:02 来自手机 | 只看该作者
这个问题,估什用setparent解决  http://answers.microsoft.com/en-us/office/forum/office_2007-access/setting-a-subforms-sourceobject-to-a-member-of-a/d9617b6c-f716-4474-a172-4f53fd15aac7

点击这里给我发消息

5#
发表于 2015-6-7 04:57:31 来自手机 | 只看该作者
有做过把Acc放到VB6的Form,实现托盘的比较有趣
6#
发表于 2015-6-8 04:18:51 | 只看该作者
{:soso_e100:}{:soso_e179:}{:soso_e113:}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-12-1 17:32 , Processed in 0.099933 second(s), 33 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表