By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

Access project + VBA

P: n/a
Hi folks,

Currently developing a project in database. The problem is my front
end and back end are in the same .mdb file but when ever i tried to
open the database connection it throws following error.

The database has been placed in a state by user '<username>' on machine
'<machine name>' that prevents it being opened or locked.

Run time error '-2147467259 (80004005)

I am also post the sample code which i had used to open the database
connection.

Private Sub Form_Load()

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
On Error GoTo MyErr

If conn.State = 1 Then
conn.Close
Else
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
CurrentProject.Path & "\login.mdb;Persist Security Info=False"
rs.Open "select * from login", conn, adOpenDynamic,
adLockOptimistic

txtUnm.Value = rs.Fields(0)
txtPwd.Value = rs.Fields(1)

End If

MyErr:
MsgBox Err.Number & " " & Err.Description

end sub

Any help is appreciated. THANK U.

Oct 25 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi, Sajit,

"sajit" wrote...
Hi folks,

Currently developing a project in database. The problem is my front
end and back end are in the same .mdb file but when ever i tried to
open the database connection it throws following error.

Errm.... why should you open a database connection to a database that you
are already in?

At the moment you open your frontend access already opens a "connection" to
your backend - because it's in the same .mdb file.

Sounds to me like you're trying to start the car in which you are driving on
the highway. :-P

Regards

Michael
Oct 25 '06 #2

P: n/a
"sajit" <na*********@gmail.comwrote in message
<11**********************@h48g2000cwc.googlegroups .com>:
Hi folks,

Currently developing a project in database. The problem is my front
end and back end are in the same .mdb file but when ever i tried to
open the database connection it throws following error.

The database has been placed in a state by user '<username>' on
machine '<machine name>' that prevents it being opened or locked.

Run time error '-2147467259 (80004005)

I am also post the sample code which i had used to open the database
connection.

Private Sub Form_Load()

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
On Error GoTo MyErr

If conn.State = 1 Then
conn.Close
Else
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
CurrentProject.Path & "\login.mdb;Persist Security Info=False"
rs.Open "select * from login", conn, adOpenDynamic,
adLockOptimistic

txtUnm.Value = rs.Fields(0)
txtPwd.Value = rs.Fields(1)

End If

MyErr:
MsgBox Err.Number & " " & Err.Description

end sub

Any help is appreciated. THANK U.
Around here, you'll most likely get the recommandation of using DAO
on Jet tables.

I don't think I've found the need to do implicit instantiations, I
prefer being explicit.

Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
....

When working with the current project/database with ADO, try using
for instance

set conn = currentproject.connection

in stead of opening a separate connection. That's most likely the
reason for your errormessage

--
Roy-Vidar
Oct 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.