三个OptionButton,optionButton1对应text7,optionButton2对应text8,optionButton3对应text9
Dim sql As String
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
conn.Open "provider=Microsoft.Jet.OLEDB.4.0; data source=" & App.Path & "\db1.mdb"
If Option1.Value = True And Text7.Text <> "" Then
Text8.Text = ""
Text8.Text = ""
sql = "select * from Attendence where ENo='" & Text7.Text & "'"
ElseIf Option1.Value = True And Text7.Text = "" Then
MsgBox "请输入要查询的员工编号!", vbOKOnly + vbExclamation
Text7.SetFocus
End If
If Option2.Value = True And Text8.Text <> "" Then
Text7.Text = ""
Text9.Text = ""
sql = "select * from Attendence where Name='" & Text8.Text & "'"
ElseIf Option2.Value = True And Text8.Text = "" Then
MsgBox "请输入要查询的员工编号!", vbOKOnly + vbExclamation
Text8.SetFocus
End If
If Option3.Value = True And Text9.Text <> "" Then
Text7.Text = ""
Text8.Text = ""
sql = "select * from Attendence where DeptID=" & Val(Text9.Text)
ElseIf Option3.Value = True And Text9.Text = "" Then
MsgBox "请输入要查询的员工编号!", vbOKOnly + vbExclamation
Text9.SetFocus
End If
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
With DataGrid1
.AllowAddNew = False
.AllowDelete = False
.AllowUpdate = False
End With
Set DataGrid1.DataSource = rs