Access VBA是指Active Form上的文本框

时间:2015-04-14 16:37:45

标签: vba ms-access

我知道如何通过选择表单来引用表单上的项目,即Forms!frmMyForm![Control].Value。但是我有代码可以找到哪个表单是打开的,然后从该变量执行代码,但它不起作用。我想我只需要使用ActiveForm来引用控件,而不是一个明确的表单名称,但是我试图完成的事情并没有起作用。

这是我的代码。

Private Sub OrderButton_Click()
'
DoCmd.SetWarnings False
'
CurRecord = Forms!frm_EC_All![L#].Value
GetID = Forms!frm_MainMenu!AssocIDBox
'
Me.LBox.Value = CurRecord
'
If CurrentProject.AllForms("frm_EC_All").IsLoaded = True Then
    RightForm = "frm_EC_All"
ElseIf CurrentProject.AllForms("frm_EC_EC#").IsLoaded = True Then
    RightForm = "frm_EC_EC#"
ElseIf CurrentProject.AllForms("frm_EC_Holds").IsLoaded = True Then
    RightForm = "frm_EC_Holds"
ElseIf CurrentProject.AllForms("frm_EC_L1").IsLoaded = True Then
    RightForm = "frm_EC_L1"
ElseIf CurrentProject.AllForms("frm_EC_L1_L2").IsLoaded = True Then
    RightForm = "frm_EC_L1_L2"
ElseIf CurrentProject.AllForms("frm_EC_L2").IsLoaded = True Then
    RightForm = "frm_EC_L2"
ElseIf CurrentProject.AllForms("frm_EC_L34").IsLoaded = True Then
    RightForm = "frm_EC_L34"
End If
'
Me.Refresh
'
DoCmd.RunSQL "UPDATE tbl_CQueue SET Order1 = -1, Order1Date = Now WHERE [L#] = " & CurRecord
DoCmd.Close acForm, "frm_Requests", acSaveYes
DoCmd.Close acForm, RightForm, acSaveYes
'
DoCmd.OpenForm RightForm, acNormal, , , , acWindowNormal
'
Dim CurrentForm As Form: Set CurrentForm = Screen.ActiveForm
MsgBox "Current form is " & CurrentForm.Name
'
CurrentForm.TimerActivatedLabel.Visible = True
'
GetID = Forms!frm_MainMenu!AssocIDBox
CurRecord = Forms!CurrentForm![L#].Value
'
DoCmd.RunSQL "UPDATE tbl_Data SET tbl_Data.[AssocID] = " & GetID & " , tbl_Data.[tsStartAll] = Now WHERE tbl_Data.[AssocID] Is Null AND tbl_Data.[L#] = " & CurRecord
'
Forms!CurrentForm!IDFieldBox.Value = GetID
'
DoCmd.SetWarnings True
'
End Sub

我在第CurrentForm.TimerActivatedLabel.Visible = True行上收到错误消息。错误显示"Database can't find the form 'CurrentForm' referred to in a macro expression or Visual Basic code."

所以它看到后台打开了什么表单并将其存储为" RightForm",然后关闭那个表单,再次打开它,然后尝试让它工作我设置了活动表单到CurrentForm,然后它应该设置一些文本框并运行一个SQL语句等。但它需要知道表单的名称并且它没有正确抓取{ {1}}用作表单的名称。

有什么想法吗?感谢。

1 个答案:

答案 0 :(得分:0)

woops,我发布后立即找到了答案!

Screen.ActiveForm![TimerActivatedLabel].Visible = True

对我很有用。

非常感谢!