简体   繁体   English

在特定选项卡上打开窗体VBA Access 2003

[英]open form on a specific tab vba access 2003

I'd like to open a form on a specific tab. 我想在特定标签上打开表格。 The form is not the current one. 该表格不是当前表格。

Function OpenOnTab(tabIndex As Integer)
    Dim frmName As String
    Dim frm As Form
    frmName = "MyFormName"

    'open form
    DoCmd.OpenForm frmName

    'go to tab
    frm = Forms!frmName 'error "incorrect property use"

    'todo set form on tabIndex
    'maybe using frm.TabCtl0.Value = tabIndex but I con't try 

End Function

I'd like in a first time to set the form in my variable and set the form on the tabIndex 我想第一次在变量中设置表格并在tabIndex上设置表格

I'm not sure what that error is. 我不确定那个错误是什么。 Probably because you are not using the Set keyword (see below) 可能是因为您没有使用Set关键字(请参见下文)

I would go with the following : 我会选择以下内容:

Function OpenOnTab(myTabIndex As Integer)
    Dim frmName As String, frm As Form, t As Integer, ctrl As Control
    frmName = "Form1"

    'open form
    DoCmd.OpenForm frmName

    'go to tab
    Set frm = Forms(frmName)
    For Each ctrl In frm
        With ctrl
            t = -1
            On Error GoTo errHandler
            t = ctrl.TabIndex
            If t = 1 Then
                MsgBox ctrl.Name
                Forms(frmName).Form.Controls(ctrl.Name).SetFocus
                Exit Function
            End If
            On Error GoTo 0
        End With
    Next

errHandler:
    If Err.Number = 438 Then ''property not supported for labels, etc
        Resume Next
    Else
        MsgBox Err.Number & vbCrLf & Err.Description
    End If

End Function

-- Edit (different requirements) -- -编辑(不同的要求)-

Navigating to a row is different. 导航到一行是不同的。 Simply use the move operation. 只需使用移动操作。

The case for index > 1 is added because in some versions of Access, .Move 0 causes an error. 之所以添加index > 1的大小写,是因为在某些版本的Access中, .Move 0会导致错误。

Function OpenOnTab(myIndex As Integer)
    Dim frmName As String
    frmName = "Form1"

    'open form
    DoCmd.OpenForm frmName

    If myIndex > 1 Then Forms(frmName).Form.Recordset.Move myIndex - 1

exit function

我找到了解决方案:)

frm.SelTop = myTabIndex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM