Hopefully I can explain what I want to do well enough...here it goes...
I have a data entry form...the user will be entering employeeIDs. Once in normal operation, most people will be entering only their own EmpID, and they should know it, so this won't be a big problem 99% of the time once this DB goes live.
However, I need some temps to enter historical data from paper sheets into the DB. These people will not know anyone else's EmpID. I'd like to set the Student field's OnDblClick event in the subform's datasheet to open a small form with a combo box. The combo box has a list of all Employee Names, and is bound to the EmpID. Once this user enters the name, and selects the person, I have a button they can click to return to the datasheet.
I can use a function to launch the form, no problem there. But how do I return the EmpID to the field in the datasheet that was double clicked?
When user double clicks in the Student field...I want the next form to appear, and then once they type in the name and select the correct person...and then click Found Them!...I need that bound value to return.
I'd love to say I have code to share right now...but the only code I have is to launch the look up form. I'm brain farting on how to pull the value back down.
答案 0 :(得分:1)
这样做的方法是将您的小对话框形式称为“acDialog”。这将导致调用代码等待。
然后“魔术”部分就是当他们点击“发现他们”你没有关闭弹出窗体时,只需设置窗体的visible = false。这具有弹出此表单的调用代码的效果,该表单暂停以继续(当您执行此操作时,表单将退出对话框模式)。所以现在你的呼叫代码仍在继续。
所以你的代码看起来像这样:
Dim strF As String ' name of popup form
strF = "frmPopUp"
' open form, wait for user selection
DoCmd.OpenForm strF, , , , , acDialog
' if for is NOT open, then assume user hit cancel buttion
' (you should likly have a cancel button on the form - that cancel buttion will
' execute a docmd.close
If CurrentProject.AllForms(strF).IsLoaded = True Then
' grab the value of thee combbo box
strComboBoxValue = Forms(strF)!NameOfComboBox
DoCmd.Close acForm, strF
End If
如上所述,Found Them按钮后面的代码不是关闭形式,而是设置窗体visible = false(me.Visible = false),这个技巧允许调用代码继续,此时你可以检查任何表格上的价值。记住在获取值后关闭表单。
答案 1 :(得分:1)
看起来你的数据表在一个子表单中,所以还有一些工作,但如果你不想这样做,它就不必像上面的解决方案一样复杂。 @ Andre451已关闭,但您需要额外的步骤来识别表单和子表单。为了演示的目的,让我们调用表格Attendance和subform Entry然后我将调用第二个形式LookUp。因此,在子窗体字段中双击的代码当然看起来像这样:
Private Sub Student_DblClick(Cancel As Integer)
DoCmd.OpenForm "LookUp"
End Sub
你真的不需要别的东西。对于“LookUp”上的按钮,你会把它放在:
Private Sub Command2_Click()
Forms![Attendance]![Entry].Form![Student] = Forms!Lookup!Student
DoCmd.Close acForm, "LookUp"
End Sub
这应该可以让你得到你想要的东西而没有任何开销或者不得不让任何鬼魂打开。