DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
Altın Üyelik Hakkında Bilgi
Option Explicit
Sub Check_Staff_Leave()
Dim My_Date As Date, My_Connection As Object
Dim My_Recordset As Object, My_Query As String
Dim Process_Time As Double
Process_Time = Timer
Set My_Connection = VBA.CreateObject("AdoDb.Connection")
My_Connection.Open "Provider=Microsoft.Ace.OleDb.12.0;Data Source=" & _
ThisWorkbook.FullName & ";Extended Properties=""Excel 12.0;Hdr=Yes"""
My_Date = DateSerial(2022, 6, 25)
Set My_Recordset = My_Connection.Execute("Select [İZİN TÜRÜ], AYRILIS, KATILIS, GÜN From [01-1$E5:U] " & _
"Where " & CLng(My_Date) & ">= AYRILIS And " & CLng(My_Date) & "<= KATILIS")
If Not My_Recordset.EOF Then
MsgBox My_Date & " tarihinde personel izinlidir." & vbCrLf & vbCrLf & _
My_Recordset.Fields(0).Value & vbCrLf & _
My_Recordset.Fields(1).Value & vbCrLf & _
My_Recordset.Fields(2).Value & vbCrLf & _
My_Recordset.Fields(3).Value & vbCrLf & vbCrLf & _
"İşlem süresi ; " & Format(Timer - Process_Time, "0.00") & " Saniye", vbInformation
End If
If My_Recordset.State <> 0 Then My_Recordset.Close
If My_Connection.State <> 0 Then My_Connection.Close
Set My_Connection = Nothing
Set My_Recordset = Nothing
End Sub
Sub izin_kontrol()
Dim con, rs As Object
'değişken tanımlama
Dim query, ConStr, db_file As String
Dim i, sonhucre As Long
'Dim per_arr() As String
Set con = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
db_file = ThisWorkbook.FullName
con.Open = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
db_file & ";Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
sonhucre = db_izin_arsiv.Cells(6, 6).End(xlDown).row 'son boş satiri bulmak için
ARALIK = db_izin_arsiv.Name & "$" & "E5" & ":" & "Q" & sonhucre 'aralık belirle
''''KRİTERE SORGUSU
İşlem_Yap_TC = "11111111111"
tarih1 = DateSerial(2022, 6, 27)
tarih2 = "29.06.2023"
'Bu sorgu çalışıyor
'query = "SELECT * FROM [" & ARALIK & "] " & _
"WHERE AYRILIS >=" & CLng(CDate(tarih1)) & _
"and AYRILIS <=" & CLng(CDate(tarih2)) & " and [TC KİMLİK NO] = " & İşlem_Yap_TC & " "
'bu çalışmıyor
query = "SELECT * FROM [" & ARALIK & "] " & _
"WHERE AYRILIS >=" & CLng(CDate(tarih1)) & _
"and AYRILIS <=" & CLng(CDate(tarih1)) & " and [TC KİMLİK NO] = " & İşlem_Yap_TC & " "
rs.Open query, con, 3, 1
If rs.RecordCount >= 1 Then: MsgBox "Personel İzinde"
end sub
sub test2 ()
Dim con, rs As Object
'değişken tanımlama
Dim query, ConStr, db_file As String
Dim i, sonhucre As Long
'Dim per_arr() As String
Set con = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
db_file = ThisWorkbook.FullName
con.Open = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
db_file & ";Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
sonhucre = db_izin_arsiv.Cells(6, 6).End(xlDown).row 'son boş satiri bulmak için
ARALIK = db_izin_arsiv.Name & "$" & "E5" & ":" & "Q" & sonhucre 'aralık belirle
''query = "SELECT * FROM [" & ARALIK & "]" 'tüm izinleri getir
''''KRİTERE SORGUSU
İşlem_Yap_TC = "11111111111"
tarih1 = DateSerial(2022, 3, 16)
tarih2 = "29.06.2023"
''2 tarih arası işlem yapılan tc
query = "SELECT * FROM [" & ARALIK & "] " & _
"WHERE AYRILIS >=" & CLng(CDate(tarih1)) & _
"and AYRILIS <=" & CLng(CDate(tarih2)) & " and [TC KİMLİK NO] = " & İşlem_Yap_TC & " "
rs.Open query, con, 3, 1
MsgBox rs.Fields.Item(7).Value
'RecordSet sonuçlarını belirli alanlara yazdırmak için döngü
Do Until rs.EOF 'until true olana kadar döngü döner
'MsgBox rs.Fields.Item(2).Value 'izin ayrılıs tarihi
ayrılıs = CLng(CDate(rs.Fields.Item(7).Value))
katılıs = CLng(CDate(rs.Fields.Item(8).Value))
tarih2 = CLng(CDate(tarih2))
If tarih2 >= ayrılıs And tarih2 < katılıs Then
MsgBox "İzinde"
End If
rs.movenext 'bir sonraki değere
Loop
rs.close
end sub
Sub izin_kontrol()
Dim con, rs As Object
Dim query, db_file As String
Dim i, sonhucre As Long
Set con = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
db_file = ThisWorkbook.FullName
con.Open = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
db_file & ";Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
sonhucre = db_izin_arsiv.Cells(6, 6).End(xlDown).row 'son boş satiri bulmak için
ARALIK = db_izin_arsiv.Name & "$" & "E5" & ":" & "Q" & sonhucre 'aralık belirle
query = "SELECT * FROM [" & ARALIK & "] " & _
"WHERE AYRILIS >=" & CLng(CDate(tarih1)) & _
"and KATILIS <" & CLng(CDate(tarih1)) & " and [TC KİMLİK NO] = " & İşlem_Yap_TC & " "
rs.Open query, con, 3, 1
MsgBox rs.RecordCount
rs.Close
End Sub
İşlem_Yap_TC = "11111111111"
tarih1 = "01.01.2022"
tarih2 = "29.12.2022"
tarih3 = "27.06.2022"
''2 tarih arası işlem yapılan tc
query = "SELECT * FROM [" & ARALIK & "] " & _
"WHERE AYRILIS >=" & CLng(CDate(tarih1)) & _
"and KATILIS <=" & CLng(CDate(tarih2)) & " and [TC KİMLİK NO] = " & İşlem_Yap_TC & " "
'query = "SELECT * FROM [" & ARALIK & "] " & _
' "WHERE AYRILIS >=" & CLng(CDate(tarih1)) & _
' "and KATILIS <" & CLng(CDate(tarih1)) & " and [TC KİMLİK NO] = " & İşlem_Yap_TC & " "
rs.Open query, con, 3, 1
'MsgBox rs.Fields.Item(7).Value
'RecordSet sonuçlarını belirli alanlara yazdırmak için döngü
Do Until rs.EOF 'until true olana kadar döngü döner
If CLng(CDate(tarih3)) >= CLng(CDate(rs.Fields.Item(7).Value)) And CLng(CDate(rs.Fields.Item(8).Value)) > CLng(CDate(tarih3)) Then
MsgBox "AKTİF SIRA:" & rs.Fields.Item(0).Value & vbCrLf & "AKTİF TARİH:" & tarih2 & vbCrLf & "Ayrlıs:" & rs.Fields.Item(7).Value & vbCrLf & "Katılıs:" & rs.Fields.Item(8).Value
End If
rs.movenext 'bir sonraki değere
Loop
Paylaştığınız kod bloğunda kullandığınız değişkenleri göremiyorum.
ARALIK ?
tarih1 ?
İşlem_Yap_TC ?
Birde büyüklük ve küçüklük sorgusunda kriterlerinizin yerini değiştirip deneyiniz.
Sub izin_kontrol()
Dim con, rs As Object
Dim query, db_file As String
Dim i, sonhucre As Long
Set con = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
db_file = ThisWorkbook.FullName
con.Open = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
db_file & ";Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
sonhucre = db_izin_arsiv.Cells(6, 6).End(xlDown).row 'son boş satiri bulmak için
ARALIK = db_izin_arsiv.Name & "$" & "E5" & ":" & "Q" & sonhucre 'aralık belirle
''''KRİTERE SORGUSU
İşlem_Yap_TC = "11111111111"
tarih1 = "01.01.2022"
tarih2 = "29.12.2022"
tarih3 = "27.06.2022"
query = "SELECT * FROM [" & ARALIK & "] " & _
"WHERE AYRILIS >=" & CLng(CDate(tarih1)) & _
"and KATILIS <" & CLng(CDate(tarih1)) & " and [TC KİMLİK NO] = " & İşlem_Yap_TC & " "
rs.Open query, con, 3, 1
MsgBox rs.RecordCount
rs.Close
End Sub
Sub izin_kontrol()
Dim con, rs As Object
Dim query, db_file As String
Dim i, sonhucre As Long
Set con = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
db_file = ThisWorkbook.FullName
con.Open = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
db_file & ";Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
sonhucre = db_izin_arsiv.Cells(6, 6).End(xlDown).Row 'son boş satiri bulmak için
ARALIK = db_izin_arsiv.Name & "$" & "E5" & ":" & "Q" & sonhucre 'aralık belirle
''''KRİTERLER
İşlem_Yap_TC = 11111111111#
tarih1 = "25.06.2022"
query = "Select * From [" & ARALIK & "] " & _
"Where " & CLng(CDate(tarih1)) & ">= AYRILIS " & _
"And " & CLng(CDate(tarih1)) & "<= KATILIS And [TC KİMLİK NO] = " & İşlem_Yap_TC
rs.Open query, con, 3, 1
MsgBox rs.RecordCount
rs.Close
End Sub