现在稍微改了一下,运行没有错误了,但是。。。问题又出来了,选择查询过后能显示表头,但显示不出选择的职工号的信息,我郁闷,不太懂这个东西,找不到问题所在,请高手指点一下,急用,谢谢啦!
Dim str As String
Dim rs As ADODB.Recordset
Dim conn As ADODB.Connection
Private Sub Command1_Click()
考勤记录.Show
Unload 按职工号查询
End Sub
Private Sub Command2_Click()
Dim i As Integer
str = Combo1.Text
Adodc1(1).RecordSource = "select * from 加班 where 职工号='&str&'"
Adodc1(2).RecordSource = "select * from 请假 where 职工号='&str&'"
Adodc1(3).RecordSource = "select * from 考勤统计 where 职工号='&str&'"
Adodc1(4).RecordSource = "select * from 出差 where 职工号='&str&'"
If Option1(0).Value = False And Option1(1).Value = False And Option1(2).Value = False And Option1(3).Value = False Then
MsgBox ("请先选择查询项目再查询!")
End If
For i = 0 To 3
If Option1(i).Value = True Then
Set DataGrid1.DataSource = Adodc1(i + 1)
DataGrid1.Refresh
End If
Next i
End Sub
Private Sub Form_Load()
Adodc1(0).Visible = False
Adodc1(1).Visible = False
Adodc1(2).Visible = False
Adodc1(3).Visible = False
Adodc1(4).Visible = False
Set conn = New ADODB.Connection
conn.Open "mydata"
Set rs = New ADODB.Recordset
rs.Open "select * from 职工", conn, adOpenDynamic, adLockOptimistic
rs.MoveFirst
While Not rs.EOF
Combo1.AddItem rs.Fields("职工号")
rs.MoveNext
Wend
Set rs = Nothing
End Sub