- Katılım
- 2 Mart 2005
- Mesajlar
- 2,960
- Excel Vers. ve Dili
-
ev: Ofis 2007- Win Xp
iş: Ofis 2010- Win Vista
Kod:
Private Sub UserForm_Initialize()
On Error Resume Next
Dim Baglanti As ADODB.Connection: Dim Kayit1 As ADODB.Recordset: Dim SQLStr As String
Dim i As Integer
ckURN = Application.ThisWorkbook.Path & "\" & "vt_URUN.xls"
SQLStr = "SELECT DISTINCT genel FROM [DATA$]"
'************************************************'Kaynak çalışma kitabı Kontrolü
If Dir(ckURN) = "" Then
MsgBox ckURN & " " & Chr(10) & " Dosyası Bulunamadı.", vbInformation, "Bilgi": Exit Sub
End If
Set Baglanti = CreateObject("ADODB.Connection")
With Baglanti
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Extended Properties").Value = "Excel 8.0"
.Properties("Data Source").Value = ckURN
.CursorLocation = adUseClient
.Mode = adModeReadWrite
.CommandTimeout = 60
'.Properties("User ID") = vbNullString
'.Properties("Password") = vbNullString
.Open
End With
Set Kayit1 = CreateObject("ADODB.Recordset")
With Kayit1
.ActiveConnection = Baglanti
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Source = SQLStr
.Open
End With '<bitti
'************************************************'bitti<
'************************************************'verileri çek
Kayit1.MoveFirst: ComboBox1.Clear
For i = 1 To Kayit1.RecordCount
ComboBox1.AddItem Kayit1.Fields("genel")
Kayit1.MoveNext
Next i
Kayit1.MoveFirst: ComboBox1.ListIndex = 0
'************************************************'bitti<
'************************************************'bağlantıyı kes
If CBool(Kayit1.State And adStateOpen) = True Then Kayit1.Close: Set Kayit1 = Nothing
If CBool(Baglanti.State And adStateOpen) = True Then Baglanti.Close: Set Baglanti = Nothing 'bitti
End Sub