Office中国论坛/Access中国论坛
标题: 国外看到的有关多窗体的用法(使用集合Collection,做成了类)有部分代码可参考一下 [打印本页]
作者: tmtony 时间: 2015-6-6 08:20
标题: 国外看到的有关多窗体的用法(使用集合Collection,做成了类)有部分代码可参考一下
国外看到的有关多窗体的用法(使用集合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
作者: huangli0356 时间: 2015-6-6 14:25
{:soso_e177:}
作者: zpy2 时间: 2015-6-7 04:55
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
作者: zpy2 时间: 2015-6-7 04:56
这个问题,估什用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
作者: zpy2 时间: 2015-6-7 04:57
有做过把Acc放到VB6的Form,实现托盘的比较有趣
作者: friendship 时间: 2015-6-8 04:18
{:soso_e100:}{:soso_e179:}{:soso_e113:}
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) |
Powered by Discuz! X3.3 |