|
Private Sub ExportEmp_Click()
Dim sqlstr As String
Dim sqlstr2 As String
Dim sqlstr3 As String
Dim sqlstr4 As String
On Error GoTo Err_ExportEmp_Click
sqlstr = "CREATE table ExportEmployee (empno Number,name text," _
& "position text,dept text,supervisor text,SD Datetime,lastreviewby text," _
& "lastreviewdate datetime,salary number,jobgrade text,quartile number,OBJA memo,OBJQ memo);"
DoCmd.RunSQL sqlstr
sqlstr2 = "insert into ExportEmployee select * from Employee"
If (Forms!ExportEmployee!empno.Value <> 0) Then
sqlstr3 = "empno=" & Forms!ExportEmployee!empno.Value
End If
If (Forms!ExportEmployee!name.Value <> "") Then
If (sqlstr3 <> "") Then
sqlstr3 = sqlstr3 & " and "
End If
sqlstr3 = sqlstr3 & "name='" & Forms!ExportEmployee!name.Value & "'"
End If
If (Forms!ExportEmployee!SDfrom.Value <> "") Then
If (sqlstr3 <> "") Then
sqlstr3 = sqlstr3 & " and "
End If
sqlstr3 = sqlstr3 & "SD>=" & "#" & Forms!ExportEmployee!SDfrom.Value & "#"
End If
If (Forms!ExportEmployee!SDto.Value <> "") Then
If (sqlstr3 <> "") Then
sqlstr3 = sqlstr3 & " and "
End If
sqlstr3 = sqlstr3 & "SD<=" & "#" & Forms!ExportEmployee!SDto.Value & "#"
End If
If (Forms!ExportEmployee!dept.Value <> "") Then
If (sqlstr3 <> "") Then
sqlstr3 = sqlstr3 & " and "
End If
sqlstr3 = sqlstr3 & "dept='" & Forms!ExportEmployee!dept.Value & "'"
End If
sqlstr3 = sqlstr2 & " where " & sqlstr3 & ";"
If IsNull(Forms!ExportEmployee!empno.Value) And IsNull(Forms!ExportEmployee!name.Value) And IsNull(Forms!ExportEmployee!SDfrom.Value) And _
IsNull(Forms!ExportEmployee!SDto.Value) And IsNull(Forms!ExportEmployee!dept.Value) Then
sqlstr = sqlstr2 & ";"
DoCmd.RunSQL sqlstr
Else
DoCmd.RunSQL sqlstr3
End If
DoCmd.OutputTo acOutputTable, "ExportEmployee", acFormatXLS, , True
DoCmd.Close acForm, "ExportEmployee"
sqlstr4 = "drop table ExportEmployee;"
DoCmd.RunSQL sqlstr4
Exit_ExportEmp_Click:
Exit Sub
Err_ExportEmp_Click:
'MsgBox Err.description
sqlstr4 = "drop table ExportEmployee;"
DoCmd.RunSQL sqlstr4
Resume Exit_ExportEmp_Click
End Sub |
|