把B的控件来源去掉,在A的打开窗体事件中增加一句:Forms!B!ITEM = Forms!A!ITEM
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "B"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!B!ITEM = Forms!A!ITEM
Exit_Command2_Click:
Exit Sub
Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click
End Sub
思路:
首先在你打开B窗体的时候要判断A窗体有没有打开。
如果打开了:B![ITEM]=forms!A!item
否则:B![ITEM]=""
实现:
免费赠送一个判断窗体是否打开的函数:其实是ACCESS软件网里面淘来的
Public Function IsLoaded(ByVal strFormName As String) As Boolean
'判断窗体是否加载的函数
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function
把B窗体ITEM控件中的 = Form_A.ITEM清除,再在B窗体加载事件中写:
Private Sub Form_Load()
If IsLoaded("A") Then
Me.ITEM = Form_A.ITEM
End If
End Sub
点击下载此附件
木头人老师看看系统的错误提示!
总记录:3篇 页次:1/1 9 1 :