Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database Access

Status
Not open for further replies.

joinme

IS-IT--Management
Jan 12, 2003
20
DE
Hi,

Can someone show me how to open an access table using ADODB ConnectionString?

Many thanks.

JM
 
Here you Go

Sub ConnectDB()

hDBConnect.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info = False;Data Source = " & sDBasePath
hDBConnect.Mode = adModeReadWrite
hDBConnect.Open
CType = adOpenStatic
CLocation = adUseServer

End Sub

Note the sDBasePath is a string variable that has been assigned the database path ie sDBasePath = "C:\myDBase.mdb"

Hope this helps Anything is possible, the problem is I only have one lifetime.
[cheers]
 
And how can I add records to that Table?
 
What table? All the above code does is establish a connection to the database.

Here is some code to connect and then update a table

Private hDB As New ADODB.Connection
Private rsData As New ADODB.Recordset

Private Function ConnectDB() As Boolean
Dim sTmp As String

sTmp = "C:\myDBase.mdb

On Error GoTo ErrHnd

hDB.ConnectionString = sTmp
hDB.Mode = adModeReadWrite
hDB.Open
If rsData.State = adStateOpen Then
rsData.Close
End If
With rsData
.ActiveConnection = hDB
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "myTable"
End With

Do Until rsData.EOF
rsData("myField") = "Changed Value"
rsData.MoveNext
Loop
rsData.Close
ConnectDB = True
Exit Function

ErrHnd:
MsgBox Err.Number & " " & Err.Description & " Error Generated By " & Err.Source, vbCritical, "System Error Trap !"
ConnectDB = False
End Function

myDBase.mdb is The Access db Name
myTable is a Table in that db
myField is a Column in that table


Hope this helps Anything is possible, the problem is I only have one lifetime.
[cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top