在MS Access中引用可重用表单(2深) [英] Referencing reusable forms (2 deep) in MS Access
问题描述
我有多个会员,每个会员都有一个包含多个备忘录字段的记录:
I have multiple Members, and each one has a record which contains several memo fields:
Member ID Entry A Entry B
1 [memo text] [memo text]
2 [memo text] [memo text]
3 [memo text] [memo text]
在Access 2007中,我创建了一个与 Shift-F2
- 一个专门的窗口,以审查和编辑内容。与 Shift-F2
不同,这必须是可重用的。
In Access 2007, I am creating a Memo Entry form that is the equivalent of Shift-F2
-- A dedicated window to review and edit the content. Unlike Shift-F2
, this must be reusable.
我必须提到,用于显示会员详细信息的表单也可以重复使用。按照上面的计划(简称),我最多可以同时打开三个会员表格和六个备忘录输入表单。
I must mention that the form for showing details about a Member is also reusable. Following the plan above (which is abbreviated), I could have up to three Member forms and six Memo Entry forms open at once.
以下解决方案效果很好,除非关键事件 UpdateComment()
每个备忘录一次。因此,如果我为同一成员打开 A 和 B ,并进行修改,则只有一个编辑将传递到调用表单。
The solution below works well EXCEPT that the critical event UpdateComment()
is only triggered once per Member-form instead of once per Memo-form. So if I open A and B for the same member and make edits, only one edit will be passed to the calling form.
我无法提供调用表单会员详细信息
,使用一种方法来处理备忘录表单独特。如何解决这个问题?
Somehow I am failing to provide the calling form, Member Detail
, with a method to treat the Memo forms as unique. How do I solve that?
Dim strFieldName As String, varValue
Private WithEvents frmZoom As Form_frmMemberInputZoom
Private Sub btnView_A_Click()
strFieldName = "boxQuality_A"
varValue = Me(strFieldName)
Call OpenMemberInput(Me!boxID, strFieldName, varValue, True)
End Sub
Private Sub btnView_B_Click()
strFieldName = "boxQuality_B"
varValue = Me(strFieldName)
Call OpenMemberInput(Me!boxID, strFieldName, varValue, True)
End Sub
Private Sub frmZoom_UpdateComment(lngID As Long, _
strAssessStage As String, varReturn)
Dim intCount As Integer
For intCount = 1 To collectnZooms.Count
If collectnZooms(intCount)![boxID] = lngID _
And collectnZooms(intCount)![boxAssessStage] = strAssessStage _
Then
Me(strAssessStage) = varReturn
Me.Dirty = False
Exit Sub
End If
Next
End Sub
Private Sub Form_Close()
Dim obj As Object
For Each obj In collectnMembers
If obj.Hwnd = Me.Hwnd Then
collectnMembers.Remove CStr(Me.Hwnd)
End If
Next
End Sub
Sub OpenMemberInput(lngID As Long, strStage As String, _
varComment, booEdit As Boolean)
Set frmZoom = New Form_frmMemberInputZoom
frmZoom.Caption = CStr(frmZoom.Hwnd)
frmZoom.ID = lngID
frmZoom.Stage = strStage
frmZoom.ProviderName = "Dr " & CStr(lngID)
frmZoom.Comment = varComment
frmZoom.Visible = True
collectnZooms.Add Item:=frmZoom, Key:=CStr(frmZoom.Hwnd)
End Sub
备注输入表单 - / h3>
Memo Entry form -- this one is spawned
Public Event UpdateComment(lngID As Long, strAssessStage As String, _
varReturn)
Private lngAssess_ID As Long
Private strAssessStage As String
Private strProviderName As String
Private varComment
Public Property Let ID(ByVal MyAssessID As Long)
lngAssess_ID = MyAssessID
Me.boxID = lngAssess_ID
End Property
Public Property Let Stage(ByVal MyAssessStage As String)
strAssessStage = MyAssessStage
Me.boxAssessStage = strAssessStage
End Property
Public Property Let ProviderName(ByVal MyProviderName As String)
strProviderName = MyProviderName
Me.boxProviderName = strProviderName
End Property
Public Property Let Comment(ByVal varExisting)
varComment = varExisting
Me.boxComment = varComment
End Property
Public Property Get Comment()
Comment = varComment
End Property
Private Sub boxComment_AfterUpdate()
varComment = Me.boxComment
Comment = varComment
End Sub
Private Sub Form_Close()
'#################################################################
' Line below will be called for only ONE of the multiple instances
'#################################################################
RaiseEvent UpdateComment(lngAssess_ID, strAssessStage, varComment)
Dim obj As Object
For Each obj In collectnZooms
If obj.Hwnd = Me.Hwnd Then
collectnZooms.Remove CStr(Me.Hwnd)
End If
Next
End Sub
推荐答案
=http://stackoverflow.com/a/3731712/122139>此帖:
As recommended in this post:
- 解除
RaiseEvent
函数。 - 使用
.Visible
可避免关闭备忘录条目表单(这会抛出异常)。
- Dismantle the
RaiseEvent
function. - Use
.Visible
to avoid closing out the Memo Entry form (which throws things off).
Dim strFieldName As String, varValue
'Private WithEvents ... NAH, WE WON'T GO THERE
Private Sub btnView_A_Click()
strFieldName = "boxQuality_A"
varValue = Me(strFieldName)
Call OpenMemberInput(Me!boxID, strFieldName, varValue, True)
End Sub
Private Sub btnView_B_Click()
strFieldName = "boxQuality_B"
varValue = Me(strFieldName)
Call OpenMemberInput(Me!boxID, strFieldName, varValue, True)
End Sub
'Private Sub frmZoom_UpdateComment(lngID As Long, strAssessStage As String, varReturn)
' ... NAH, we won't be using this...
'End Sub
Private Sub Form_Close()
Dim obj As ObjecT
For Each obj In collectnMembers
If obj.Hwnd = Me.Hwnd Then
collectnMembers.Remove CStr(Me.Hwnd)
End If
Next
End Sub
Sub OpenMemberInput(lngID As Long, strStage As String, _
varComment, booEdit As Boolean)
Dim FoundMe As Boolean
FoundMe = v_MemberComment.FetchForm(lngID, strStage)
If FoundMe Then Exit Sub
Dim frmZoom As New Form_frmMemberInputZoom
Set frmZoom = New Form_frmMemberInputZoom
frmZoom.ID = lngID
frmZoom.Stage = strStage
frmZoom.Comment = varComment
frmZoom.Visible = True
collectnZooms.Add Item:=frmZoom, Key:=CStr(frmZoom.Hwnd)
End Sub
备注输入表单 - 生成此表单
Memo Entry form -- this one is spawned
'' NAH, no use of the Public Event
'Public Event UpdateComment(lngID As Long, strAssessStage As String, varReturn)
Private lngAssess_ID As Long
Private strAssessStage As String
Private varComment
Public Property Let ID(ByVal MyAssessID As Long)
lngAssess_ID = MyAssessID
Me.boxID = lngAssess_ID
End Property
Public Property Let Stage(ByVal MyAssessStage As String)
strAssessStage = MyAssessStage
Me.boxAssessStage = strAssessStage
End Property
Public Property Let Comment(ByVal varExisting)
varComment = varExisting
Me.boxComment = varComment
End Property
Public Property Get Comment()
Comment = varComment
End Property
Private Sub boxComment_AfterUpdate()
varComment = Me.boxComment
Comment = varComment
End Sub
Private Sub CmdCancel_Click()
''TODO revert to before-update text if Cancel is selected
Me.Tag = "Cancel"
Me.Visible = False
End Sub
Private Sub CmdOK_Click()
Dim intCount As Integer, frm As Form, lngHwnd As Long
For intCount = 1 To collectnMembers.Count
Set frm = collectnMembers(intCount)
If frm![boxID] = lngAssess_ID Then
frm(strAssessStage) = varComment
frm.Requery
End If
Next
Me.Visible = False
End Sub
Private Sub Form_Close()
'RaiseEvent .... NAH, DON'T BOTHER
Dim obj As Object
For Each obj In collectnZooms
If obj.Hwnd = Me.Hwnd Then
collectnZooms.Remove CStr(Me.Hwnd)
End If
Next
End Sub
VBA标准模块以支持上述形式
VBA Standard Module to support above form
Public collectnZooms As New Collection
Public Function FetchForm(lngID As Long, strStage As String) As Boolean
Dim intCount As Integer
For intCount = 1 To collectnZooms.Count
If collectnZooms(intCount)![boxID] = lngID _
And collectnZooms(intCount)![boxAssessStage] = strStage Then
FetchForm = True
collectnZooms(intCount).Tag = ""
collectnZooms(intCount).Visible = True
Exit Function
End If
Next
End Function
这篇关于在MS Access中引用可重用表单(2深)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!