[attach]40653[/attach]
1、写一个窗体的子程序
Private Sub MyTab(myField As String)
Dim ctls As Controls
Dim rs As New ADODB.Recordset
Dim ssql As String
Dim i As Long
ssql = "select * from 索引排序表"
rs.Open ssql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Set ctls = Me.Form.Controls
For i = 1 To rs.RecordCount
ctls(rs("字段")).TabIndex = rs(myField)
rs.MoveNext
Next
End Sub
2、引用该子程序
Private Sub 更改索引_Click()
Dim a As Long
a = nz(InputBox("请选择顺序:1=原顺序;2=现顺序"),1)
Select Case a
Case 1
Call MyTab("原顺序")
Case 2
Call MyTab("现顺序")
Case Else
MsgBox "选择错误!"
End Select
End Sub
Option Compare Database
Const TabMax As Integer = 8
Private Sub 更改索引_Click()
Dim ctls As Controls
Set ctls = Me.Form.Controls
Select Case Me.选项
Case 1
If ctls(Me.控件.Value).TabIndex > 0 Then
ctls(Me.控件.Value).TabIndex = ctls(Me.控件.Value).TabIndex - 1
Me.Tab.Value = ctls(Me.控件.Value).TabIndex
End If
Case 2
If ctls(Me.控件.Value).TabIndex < TabMax Then
ctls(Me.控件.Value).TabIndex = ctls(Me.控件.Value).TabIndex + 1
Me.Tab.Value = ctls(Me.控件.Value).TabIndex
End If
End Select
End Sub
Private Sub 工号_GotFocus()
Me.控件.Value = Me.ActiveControl.Name
Me.Tab.Value = Me.ActiveControl.TabIndex
End Sub
Private Sub 工量ID_GotFocus()
Me.控件.Value = Me.ActiveControl.Name
Me.Tab.Value = Me.ActiveControl.TabIndex
End Sub