VB中至少一个对象没有指定值,然后就出现对象关闭时,不允许操作
Option Explicit
Private strQuery As String
Private fromtime As String '开始时间
Private totime As String '结束时间
Private Sub CmdCancel_Click()
Unload Me
Exit Sub
End Sub
Private Sub setstrQuery()
fromtime = Me.SYear & "-" & Me.SMonth & "-1" & "-" & Me.SDay & "-2"
totime = Me.EYear & "-" & Me.EMonth & "-1" & "-" & Me.EDay & "-2"
If Me.IDchecked.Value = vbChecked And Me.Timechecked.Value = vbChecked Then
strQuery = "select * from 改变信息 where AID='" & Me.StuffID
strQuery = strQuery & "' and OutTime between #" & fromtime & "# and #"
strQuery = strQuery & totime & "#"
MsgBox strQuery
ElseIf Me.IDchecked.Value = vbChecked Then
strQuery = "select * from 改变信息 where AID='" & Me.StuffID & "' order by ID"
ElseIf Me.Timechecked.Value = vbChecked Then
strQuery = "select * from 改变信息 where OutTime between #" & fromtime
strQuery = strQuery & "# and #" & totime & "# order by ID"
Else
strQuery = "select * from 改变信息 order by ID"
End If
End Sub
Private Sub CmdOk_Click()
Call setstrQuery
TurnInfoRS.Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\员工.mdb"
TurnInfoRS.Adodc1.RecordSource = strQuery
If strQuery <> "" Then
frmAlterationResult.Adodc1.Refresh
End If
Set TurnInfoRS.DataGrid1.DataSource = TurnInfoRS.Adodc1.Recordset
TurnInfoRS.DataGrid1.Refresh
TurnInfoRS.Show
TurnInfoRS.ZOrder 0
Unload Me
End Sub
Private Sub Form_Load()
Dim i, j As Integer
Dim SQL As String
Dim rs As New ADODB.Recordset
SQL = "select distinct AID from 改变信息 order by AID"
Set rs = TransactSQL(SQL)
If rs.EOF = False Then
rs.MoveFirst
While Not rs.EOF
Me.StuffID.AddItem rs(0)
rs.MoveNext
Wend
Me.StuffID.ListIndex = 0
End If
rs.Close
SQL = "select distinct OutTime from 改变信息"
Set rs = TransactSQL(SQL)
If Not rs.EOF Then
rs.MoveFirst
While Not rs.EOF
If Not IsNull(rs.Fields(0)) Then '设置年
Me.SYear.AddItem Left(rs(0), 4)
Me.EYear.AddItem Left(rs(0), 4)
End If
rs.MoveNext
Wend
rs.Close
Me.SYear.ListIndex = 0
Me.EYear.ListIndex = 0
End If
For i = 1 To 12 '设置月
Me.SMonth.AddItem i
Me.EMonth.AddItem i
Next i
Me.SMonth.ListIndex = 0
Me.EMonth.ListIndex = 0
For j = 1 To 30 '设置日
Me.SDay.AddItem j
Me.EDay.AddItem j
Next j
Me.SDay.ListIndex = 0
Me.EDay.ListIndex = 0
End Sub
还有那个日的设置不会弄,因为有一个月中有30也有31,平年闰年2月份也不同 帮帮忙哦(*^__^*) 嘻嘻……
[解决办法]
sql语句有问题。