PDA

View Full Version : not able to connect access databse via vb6.0


traceMe
10-31-03, 04:33 AM
I have access database and vb6.0 to work on. i dont know how to connect the database through vb here is the code that i have written
i get "unrecognized database format 'd:\shop\shop.mdb'."
i have set references to microsoft ActiveX Data Objects 2.0 Library
is there any other references that i have to set to access ms access database
This is my code which is placed in onclick action of button

Set conShop = New Connection
Set rsShop = New Recordset
With conShop
.Provider = "MICROSOFT.JET.OLEDB.3.51"
.ConnectionString = "data Source= d:/shop/shop.mdb"
.Open
End With

rsShop.Open "select * From [user] where username='" & Trim(txtName.Text) & "' and pwd='" & Trim(txtPwd.Text) & "'", conShop, adLockOptimistic, adOpenDynamic
If txtName = "test" Then
frmAdmin.Show
Else
MsgBox "Incorrect Username Or Password"
End If

this is really very urgent if people can help me
that would be great full

Huuf
10-31-03, 05:06 PM
Option Explicit
Dim DbaseConn As ADODB.Connection
Dim RecSet As ADODB.RecordSet
Dim RecSet2 As ADODB.RecordSet
Dim SQL As String

Public Sub AddATable()
On Error Resume Next
SQL = "CREATE TABLE NAME_OF_TABLE (Fields MEMO);"
Call RecordSet
Conn
DbaseConn.Execute SQL
Dim blnTrue As Boolean
Dim tel, Tempe
Dim FreeF
FreeF = FreeFile
'Add Values
SQL = "SELECT Fields FROM NAME_OF_TABLE"
Call RecordSet
RecSet.Open (SQL)
RecSet.AddNew
RecSet("Fields") = "test
RecSet.Update
End Sub

Public Sub Conn()
Set DbaseConn = New ADODB.Connection
DbaseConn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= d:/shop/shop.mdb;"
End Sub

Public Sub RecordSet()
Set RecSet = New ADODB.RecordSet
RecSet.ActiveConnection = DbaseConn
RecSet.CursorLocation = adUseClient
RecSet.CursorType = adOpenDynamic
RecSet.LockType = adLockOptimistic
End Sub

Private Sub Form_Load()
AddATable
End Sub

traceMe
11-01-03, 12:37 AM
hey,
used this code and its working fine now able to communicate to db.
thx for ur help.....