473,382 Members | 1,238 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

VBA on Access Click Event Returns DB Error

3
I have a form with a button that when clicked should perform the following action on the current DB;

Open table TEMP and allow reading of the TEMP's "Sector" field to be stored in a variable for later comparison and update. Before I could even start coding the logic, I am getting the following error from access:

"The database has been placed in a state by user that prevents it from being opend or locked."

Here is my code (FYI: logic portion not complete yet):

Private Sub Command0_Click()
Dim myConnection As ADODB.Connection
Dim myRecordset As ADODB.Recordset
Dim pathstring As String
Dim str As String

Set myConnection = New ADODB.Connection
Set myRecordset = New ADODB.Recordset
pathstring = Application.CurrentProject.FullName


str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & pathstring & ";Persist Security Info=False"
myConnection.ConnectionString = str

'-Open the Connection --
myConnection.Open

'Determine if we conected.
If myConnection.State = adStateOpen Then

myRecordset.Open "Select * From TEMP", myConnection, adOpenDynamic, adLockOptimistic, adCmdText

Else
MsgBox "The connection could not be made."
myConnection.Close
Exit Sub
End If

'-just to be sure --
myRecordset.MoveFirst

On Error GoTo transError

'-here is the top of the transaction--
myConnection.BeginTrans

While Not myRecordset.EOF
mcounter = mcounter + 1

myRecordset!Sector = "5"
myRecordset.Update
myRecordset.MoveNext
Wend


myConnection.Close
myRecordset.Close
myConnection.Close

Exit Sub

transError:
myConnection.RollbackTrans
myRecordset.Close
myConnection.Close
MsgBox Err.Description

End Sub
Feb 20 '08 #1
4 1529
sierra7
446 Expert 256MB
Hi
I'm not clear that the Table [TEMP] is in a remote database. If not you do not need all the connection string code.
You can lookup one value with
Expand|Select|Wrap|Line Numbers
  1. myVariable = DLookup("[Sector]", "TEMP", strCriteria)
The comma and strCriteria can be ommitted if you only have one record otherwise the strCriteria must state which record you want to look at e.g. "[ID]=1" or something. Your code would return all the values in [TEMP] unless you only have one record.

I have seen various syntax for connection strings. Check out this MS Article For ADODB it should look somethig like.

cnn1.ConnectionString = "driver={SQL Server};" & _
"server=srv;uid=sa;pwd=pwd;database=Pubs"

I believe that 'Persist Secuitity Info = False' is something to do with ADO.NET, which brings us full circle, What are you using ?
S7
Feb 22 '08 #2
luvbug
3
Sorry for the late reply and thanks. The database is not remote so I will remove the unessary connection string code and use the "DLookup".

Hi
I'm not clear that the Table [TEMP] is in a remote database. If not you do not need all the connection string code.
You can lookup one value with
Expand|Select|Wrap|Line Numbers
  1. myVariable = DLookup("[Sector]", "TEMP", strCriteria)
The comma and strCriteria can be ommitted if you only have one record otherwise the strCriteria must state which record you want to look at e.g. "[ID]=1" or something. Your code would return all the values in [TEMP] unless you only have one record.

I have seen various syntax for connection strings. Check out this MS Article For ADODB it should look somethig like.

cnn1.ConnectionString = "driver={SQL Server};" & _
"server=srv;uid=sa;pwd=pwd;database=Pubs"

I believe that 'Persist Secuitity Info = False' is something to do with ADO.NET, which brings us full circle, What are you using ?
S7
Feb 27 '08 #3
luvbug
3
BTW: Not using a database with password security.


Hi
I'm not clear that the Table [TEMP] is in a remote database. If not you do not need all the connection string code.
You can lookup one value with
Expand|Select|Wrap|Line Numbers
  1. myVariable = DLookup("[Sector]", "TEMP", strCriteria)
The comma and strCriteria can be ommitted if you only have one record otherwise the strCriteria must state which record you want to look at e.g. "[ID]=1" or something. Your code would return all the values in [TEMP] unless you only have one record.

I have seen various syntax for connection strings. Check out this MS Article For ADODB it should look somethig like.

cnn1.ConnectionString = "driver={SQL Server};" & _
"server=srv;uid=sa;pwd=pwd;database=Pubs"

I believe that 'Persist Secuitity Info = False' is something to do with ADO.NET, which brings us full circle, What are you using ?
S7
Feb 27 '08 #4
FishVal
2,653 Expert 2GB
Hi, luvbug.

You are opening a new connection to the same database the code is running in.
From the one hand it is just unnecessary wasting of resources as long as database already has an opened and always available ADO connection which is returned by CurrentProject.Connection property.
From the other hand after code modification and before the module is saved your database is in locked state. No wonder connection fails.

Kind regards,
Fish.
Feb 27 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: MacDermott | last post by:
I have an Access MDB which instantiates a class in a custom DLL, manipulates it for a while, then sets it equal nothing. The MDB does other things,too, and generally behaves itself as desired....
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
6
by: MS | last post by:
Access 97 here. I want a simple way to "lock" certain records on a form. Some records remain "live" until all data is available which happens over time. When all the fields are complete, I want...
6
by: fumanchu | last post by:
I've got to let end users (really just one person) load billing batch files into a third party app table. They need to specify the billing cycle name, the batch name, and the input file name and...
13
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
1
by: cpajoe2001 | last post by:
I am having an issue and after searching around online for a day and half now and finding others with the same problem but yet no solution to my issue I am looking for help. What i have is ServerA...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
5
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.