1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
(ByVal hwndParent As Long, ByVal fRequest As Long, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long
Public db As ADODB.Connection
Public dbr1 As ADODB.Recordset
Public connString As String
Public Sub Connect()
If Len(Dir$("c:\Sample.dsn")) < 1 Then
Call Create
End If
connString = "DSN=Sample;"
Set db = New ADODB.Connection
db.Open connString
Set dbr1 = New ADODB.Recordset
dbr1.Open "Your Table", db, adOpenKeyset, adLockOptimistic
End Sub
Private Function CreateAccessDSN(DSNName As String, DatabaseFullPath As String) As Boolean
Dim sAttributes As String
sAttributes = "DSN=" & DSNName & Chr(0)
sAttributes = sAttributes & "DBQ=" & DatabaseFullPath & Chr(0)
CreateAccessDSN = CreateDSN("Microsoft Access Driver (*.mdb)", sAttributes)
End Function
Private Function CreateDSN(Driver As String, Attributes As String) As Boolean
CreateDSN = SQLConfigDataSource(0&, 1, Driver, Attributes)
End Function
Private Sub Create()
Dim blnRetVal As Boolean
blnRetVal = CreateAccessDSN("SampleName", "C:\YourDatabase.mdb")
End Sub
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _ (ByVal hwndParent As Long, ByVal fRequest As Long, _ ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long Public db As ADODB.Connection Public dbr1 As ADODB.Recordset Public connString As String
Public Sub Connect() If Len(Dir$("c:\Sample.dsn")) < 1 Then Call Create End If connString = "DSN=Sample;" Set db = New ADODB.Connection db.Open connString Set dbr1 = New ADODB.Recordset dbr1.Open "Your Table", db, adOpenKeyset, adLockOptimistic End Sub
Private Function CreateAccessDSN(DSNName As String, DatabaseFullPath As String) As Boolean Dim sAttributes As String sAttributes = "DSN=" & DSNName & Chr(0) sAttributes = sAttributes & "DBQ=" & DatabaseFullPath & Chr(0) CreateAccessDSN = CreateDSN("Microsoft Access Driver (*.mdb)", sAttributes) End Function
Private Function CreateDSN(Driver As String, Attributes As String) As Boolean CreateDSN = SQLConfigDataSource(0&, 1, Driver, Attributes) End Function
Private Sub Create() Dim blnRetVal As Boolean blnRetVal = CreateAccessDSN("SampleName", "C:\YourDatabase.mdb") End Sub

Örnek bir proje için tıklayın