在特定选项卡vba access 2003上打开表单

时间:2014-02-27 08:18:53

标签: vba ms-access-2003

我想在特定标签上打开表单。 表格不是现在的表格。

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

我想第一次在我的变量中设置表单并在tabIndex上设置表单

2 个答案:

答案 0 :(得分:0)

我不确定那个错误是什么。可能是因为您没有使用Set关键字(见下文)

我会选择以下内容:

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

- 修改(不同要求) -

导航到一行是不同的。只需使用移动操作。

添加了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

答案 1 :(得分:0)

我找到了解决方案:)

frm.SelTop = myTabIndex