access ten excele şartlı veri nasıl alınır?

Katılım
7 Nisan 2007
Mesajlar
124
Excel Vers. ve Dili
office 2003
Kod:
Private Sub UserForm_Initialize()
Dim adoCN As Object
    Dim RS As Object
    Dim strSQL As String
    Dim NoA As Long
    
    DatabasePath = "deneme.mdb"
    If Dir(DatabasePath) = "" Then
        MsgBox DatabasePath & " bulunamadi, programdan cikilacak !", vbCritical, "ExcelToMDB"
        Exit Sub
    End If
    
    Set adoCN = CreateObject("ADODB.Connection")
    adoCN.Provider = "Microsoft.Jet.OLEDB.4.0"
    adoCN.ConnectionString = DatabasePath
    adoCN.Open

    NoA = Cells(65536, 1).End(xlUp).Row
    Set RS = CreateObject("ADODB.recordset")
    
    strSQL = "SELECT * FROM [tbProje]"
    
    RS.Open strSQL, adoCN, 1, 3
        RS.MoveFirst
        
      
              
        For i = 1 To RS.RecordCount
       
        
      
           Sheets("Sheet1").Cells(i, 1).Value = RS("P_Satir1")
          
           Sheets("Sheet1").Cells(i, 3) = RS("P_Durum")
           
           Sheets("Sheet1").Cells(i, 8) = RS("P_Tarih")
         
            RS.MoveNext
           
                  Next
   
    RS.Close
    adoCN.Close
    
    Set RS = Nothing
end sub
arkadaşlar şu kod ile mdb dosyasından veri alıyorum...
ancak tüm veriler bana geliyor. ben ise hepsinin gelmesini istemiyorum.
access deki P_tarih sütündani tarihler şu formatta oluyor.
20080723

ben buna göre şu şekilde bi formül yaptım ama olmadı malesef.
bunu nasıl istediğim gibi yapabilirim.
Kod:
if mid(RS("P_Tarih"),1,4)>2007 then

 RS.MoveFirst
        
      
              
        For i = 1 To RS.RecordCount
       
        
           Sheets("Sheet1").Cells(i, 1).Value = RS("P_Satir1")
          
           Sheets("Sheet1").Cells(i, 3) = RS("P_Durum")
           
           Sheets("Sheet1").Cells(i, 8) = RS("P_Tarih")
         
            RS.MoveNext
           
                  Next i
ancak isteğim verilerin hepsi malesef gelmiyor. format sorunu mu var acaba?
 
Katılım
15 Haziran 2006
Mesajlar
3,704
Excel Vers. ve Dili
Excel 2003, 2007, 2010 (TR)
sql stringini aşağıdaki gibi değiştiriniz.

Kod:
strSQL = "SELECT * FROM [tbProje] " & _
            "WHERE P_Tarih>=20070000 AND P_Tarih<=20079999"
NOT : Ben 2007 yılı için sorgu kriteri koydum siz bunları bir değişkene atayabilirsiniz.

Ayrıca, mdb dosyadaki P_Tarih alanını Date formatına çevirmeniz, sorgulama açısından daha iyi olur.
 
Üst