水平选项卡,从导航按钮中的表单获取文本值

时间:2016-12-30 05:13:32

标签: access-vba

我有主页,水平导航,其中包含许多导航按钮,在NavigationButton7下我有employeesfrm,我需要在我在家庭表格时导航Next或Previous。

该ID嵌入在employeesFrm中,因此当我在主表单上时,卸载employeesfrm而不是在主表单上的VBA代码没有提供正确的ID。

我已经尝试过Froms!home!navigationSubform!ID,但这会产生错误,因为任何其他NavigationButton8或9中的任何ID都会产生另一个结果,我不想知道其他按钮中其他表单的ID。

我担心的是在employeesfrm中的ID和Home表单文本之间有一个链接。

以下

没有任何效果
Dim MyIDS As Integer

' this is giving only the first ID number all the time.
MyIDS = Me.ID 

' this is giving error.
MyIDS = Forms![Home]![NavigationSubform].[Form]![employeesfrm]![ID]

' this is giving error.
MyIDS = Forms![Home]![NavigationSubform]![Navigationform]![studentsfrm]![ID] 

' this one works but if I am on another Navigation button,
' lets say 8 not 7, I am not interested in the number.
MyIDS = Forms![Home]![NavigationSubform].Form![ID]

我需要这个号码,对于我的书签,如果我直接在employeesfrm上,它可以正常工作,但不在主页上

enter image description here

2 个答案:

答案 0 :(得分:0)

我不确定我是否完全理解您要实现的目标,但是如何在Home窗体上使用名为EmpID的未绑定文本框,然后在Employees表单集的OnCurrent事件中

Me.Parent!EmpID = ID

如果您正在使用此功能尝试返回到您在查看其他子表单之前所使用的相同记录,那么您还需要一种方法来检测您是否正在返回此子表单,否则OnCurrent事件会让你再次回到第一个记录。因此,您可能需要在主窗体上使用复选框(chkGoToBookmark,默认值为False),以便NavigationButton7(这是加载Employees子窗体的内容,对吗?)可以勾选此框。那么Employees表单的OnCurrent事件将是:

If Me.Parent!chkGoToBookmark = True And Not IsNull(Me.Parent!EmpID) Then
    Me.RecordsetClone.FindFirst "ID=" & Me.Parent!EmpID
    Me.Bookmark = Me.RecordsetClone.Bookmark
Else
    Me.Parent!EmpID = ID
End If

请注意,如果您直接在Employees表单上,那么对Me.Parent的任何引用都会导致错误,因此您可能想要捕获此错误。

答案 1 :(得分:0)

非常感谢你。我被卡住了,我和All共享我的解决方案,但是,Horizo​​ntal Form很痛苦,真的去了Tab控件,我的问题是书签,如果你在同一个表单上很容易处理书签,但是当表格时在主(主)形式里面是导航控制然后它不容易,我做的是以下内容: 在主窗体上创建了一个名为Txtv的txt,它将从我的水平按钮内的表单中托管我的ID,以及我在下面使用的卸载和加载事件,

Private Sub Form_Unload(取消为整数)

Dim rs As DAO.Recordset

If Not IsNull(Me.Parent!txtv) Then

    Set rs = CurrentDb().OpenRecordset("bookmarktb", dbOpenDynaset)
    With rs
        .FindFirst "[Variable] = 'CustomerIDLast'"
        If .NoMatch Then
            .AddNew        'Create the entry if not found.
                ![Variable] = "CustomerIDLast"
                ![Values] = Me.Parent!txtv
                ![Description] = "Last customerID, for form " & Me.Name
            .Update
        Else
            .Edit          'Save the current record's primary key.
                ![Values] = Me.Parent!txtv
            .Update
        End If
    End With
    rs.Close
End If
Set rs = Nothing

Private Sub Form_Load()

Dim varID As Variant     Dim strIIZ As String

varID = DLookup("Values", "bookmarktb", "[Variable] = 'CustomerIDLast'")
If IsNumeric(varID) Then
    With Me.RecordsetClone
        .FindFirst "[ID] = " & strIIZ & varID & strIIZ
        If Not .NoMatch Then
            Me.Bookmark = .Bookmark
        End If
    End With
End If

End Sub

不要忘记请添加表格me.parent.txtv = ID的当前事件 因此它将使用主窗体更新ID。

我认为在拆分数据库后我会受到影响,因为我听说如果数据库被拆分,findfirst将无法正常工作。 我不确定,但它应该可以与整合的数据库一起使用,