Amigos... tenho este código que funciona com um Front accdb e Back mdb
Mas ao tentar utilizar o Back End am accdb ele diz que não foi possivel conectar a base de dados..
O que fazer?
Option Explicit
Option Base 0
' the database we'll be connecting to
'Const DBFile = "../../../GrFingerSample.mdb"
'nova tunix
Const DBFile = "GrFingerSample.accdb"
Const ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
' the connection object
Dim connection As New ADODB.connection
' Open connection
Public Function OpenDB() As Boolean
On Error GoTo cantopen
connection.Open (ConnectionString & CurrentProject.Path & "\" & DBFile)
OpenDB = True
Exit Function
cantopen:
On Error GoTo 0
OpenDB = False
End Function
' Close conection
Public Sub closeDB()
If connection.State = adStateOpen Then connection.Close
End Sub
' Clear database
Public Sub clearDB()
' run "clear" query
connection.Execute "DELETE FROM enroll"
End Sub
' Add template to database. Returns added template ID.
Public Function AddTemplate(ByRef template() As Byte) As Long
Dim rs As New ADODB.Recordset
rs.Open "enroll", connection, adOpenStatic, adLockOptimistic
' Add a new row.
rs.AddNew
rs("template") = template
rs.Update
' return ID
AddTemplate = rs("ID")
End Function
' Returns a ADODB.recordset with all enrolled templates from database.
Public Function getTemplates() As ADODB.Recordset
Dim rs As New ADODB.Recordset
rs.Open "select * from enroll", connection, adOpenDynamic, adLockReadOnly
Set getTemplates = rs
End Function
' returns template with the supplied ID.
Public Function getTemplate(ID As Long) As Byte()
Dim rs As New ADODB.Recordset
' Get query response
rs.Open "select * from enroll where ID = " & ID, connection, adOpenDynamic, adLockReadOnly
' No results?
If rs.EOF And rs.BOF Then
Dim tptVazio(0) As Byte
rs.Close
getTemplate = tptVazio
Else
' Deserialize template and return it
Dim tpt() As Byte
tpt = rs("template")
rs.Close
getTemplate = tpt
End If
End Function
Saudações
Mas ao tentar utilizar o Back End am accdb ele diz que não foi possivel conectar a base de dados..
O que fazer?
Option Explicit
Option Base 0
' the database we'll be connecting to
'Const DBFile = "../../../GrFingerSample.mdb"
'nova tunix
Const DBFile = "GrFingerSample.accdb"
Const ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
' the connection object
Dim connection As New ADODB.connection
' Open connection
Public Function OpenDB() As Boolean
On Error GoTo cantopen
connection.Open (ConnectionString & CurrentProject.Path & "\" & DBFile)
OpenDB = True
Exit Function
cantopen:
On Error GoTo 0
OpenDB = False
End Function
' Close conection
Public Sub closeDB()
If connection.State = adStateOpen Then connection.Close
End Sub
' Clear database
Public Sub clearDB()
' run "clear" query
connection.Execute "DELETE FROM enroll"
End Sub
' Add template to database. Returns added template ID.
Public Function AddTemplate(ByRef template() As Byte) As Long
Dim rs As New ADODB.Recordset
rs.Open "enroll", connection, adOpenStatic, adLockOptimistic
' Add a new row.
rs.AddNew
rs("template") = template
rs.Update
' return ID
AddTemplate = rs("ID")
End Function
' Returns a ADODB.recordset with all enrolled templates from database.
Public Function getTemplates() As ADODB.Recordset
Dim rs As New ADODB.Recordset
rs.Open "select * from enroll", connection, adOpenDynamic, adLockReadOnly
Set getTemplates = rs
End Function
' returns template with the supplied ID.
Public Function getTemplate(ID As Long) As Byte()
Dim rs As New ADODB.Recordset
' Get query response
rs.Open "select * from enroll where ID = " & ID, connection, adOpenDynamic, adLockReadOnly
' No results?
If rs.EOF And rs.BOF Then
Dim tptVazio(0) As Byte
rs.Close
getTemplate = tptVazio
Else
' Deserialize template and return it
Dim tpt() As Byte
tpt = rs("template")
rs.Close
getTemplate = tpt
End If
End Function
Saudações