473,385 Members | 1,973 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,385 software developers and data experts.

VBA: Database locked by Admin

Hello Bytes Community

I have a problem with an access DB I was hoping you could help me with

I have a MS Access 2010 database which is locking the database prior to me running the following code which takes a list from the sharepoint portal and inputs it into an array for further processing down the line

It fails on the line in Set ishare_query = dbs.QueryDefs(strqueryname), either with the database has been locked by the admin in this case me or Object Variable or With block not set

I have tried the following

1) I have compacted and repaired the database

2) I have renamed the database and then compacted and repaired it

3) I have set the properties of the database to shared

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function Retrieve_Sharepoint_Records() As Variant
  3.  
  4.     On Error GoTo ErrorHandler
  5.  
  6.         Dim dbs As DAO.Database
  7.  
  8.         Dim ishare_query As DAO.QueryDef
  9.  
  10.         Dim rstTableName As DAO.Recordset   'Your table
  11.  
  12.         Dim MyArray() As Variant            'Your dynamic array
  13.  
  14.         Dim intArraySize As Integer         'The size of your array
  15.  
  16.         Dim iCounter As Integer             'Index of the array
  17.  
  18.         DoCmd.SetWarnings False
  19.  
  20.  
  21.         strDateLimit = Format(DateAdd("m", -5, Date), "dd-mm-yyyy")
  22.  
  23.         strqueryname = "Q1"
  24.  
  25.         Set dbs = OpenDatabase("C:\Users\User\Desktop\DB1.accdb")
  26.  
  27.         Set ishare_query = dbs.QueryDefs(strqueryname)
  28.  
  29.         ishare_query.SQL = "SELECT HAWB, Orig Ctr], Dest Ctr], True Value], Undervalued.[True CUR], [Created By], " & _
  30.  
  31.         "Undervalued.Created INTO [1-T_ISHARE INFO]FROM Undervalued WHERE (((Created)>=#" & strDateLimit & "#));"
  32.  
  33.  
  34.  
  35.         DoCmd.OpenQuery "Q1", acViewNormal, acEdit
  36.  
  37.         DoCmd.OpenQuery "Q2", acViewNormal, acEdit
  38.  
  39.         ' Table 2 is generated from the query Q2
  40.         Set rstTableName = CurrentDb.OpenRecordset("2-DEDUP")
  41.  
  42.         If Not rstTableName.EOF Then
  43.  
  44.             rstTableName.MoveFirst
  45.  
  46.             rstTableName.MoveFirst
  47.  
  48.             numrecs = rstTableName.RecordCount
  49.  
  50.            'use "GetRows" method to assign to an array
  51.  
  52.             MyArray = rstTableName.GetRows(numrecs)
  53.  
  54.         End If
  55.  
  56.  
  57.  
  58.         Retrieve_Sharepoint_Records = MyArray
  59.  
  60.         Debug.Print "***Ishare Records Retrieved " & numrecs & " Rows***"
  61.  
  62. ErrorHandler:
  63.  
  64.         DoCmd.SetWarnings True
  65.  
  66.         If (Len(Err.Description) > 0) Then
  67.  
  68.             MsgBox (Err.Description)
  69.  
  70.         End If
  71.  
  72. End Function 


Anyone who can see the problem will save my sanity J

Is there a piece of code that will unlock the database if the error is thrown

Maybe there is a setting I have missed out on. Any help would be greatly appreciated
May 27 '14 #1

✓ answered by jimatqsi

Harry, it's a really bad idea to change your posts after getting feedback. It means subsequent readers can't follow the conversation and might not be able to learn what you learned during the discussion.

At this point I am not sure what problem we're trying to solve. Is the error "the database has been locked by the admin" still a problem? Is "the Object Variable or With block not set" still a problem?

I noticed your reposted code still is not moving to the end of the recordset before getting the record count.

Also, what is the name of the database this code is running in? Is it C:\Users\User\Desktop\DB1.accdb? If so, you should use
Expand|Select|Wrap|Line Numbers
  1. set dbs = currentdb 
instead of
Expand|Select|Wrap|Line Numbers
  1. set dbs = OpenDatabase("C:\Users\User\Desktop\DB1.accdb")
That alone might solve your problem with the locked database.

Jim

9 3549
jimatqsi
1,271 Expert 1GB
Harry,
About the " Object Variable or With block not set", dbs is the object variable in that line and you have not set it. The Set statement above is commented out so dbs is nothing.

I presume when you got the database locked error you were running a test where dbs was actually set?

If so, to resolve that question we need to see the SQL code from the query you're running. You can get that from the query builder in SQL view.

Jim
May 27 '14 #2
jimatqsi
1,271 Expert 1GB
Also, to get an accurate record count you need to go to the end of the recordset. So 89-93 should read
Expand|Select|Wrap|Line Numbers
  1.             rstTableName.MoveLast
  2.  
  3.             numrecs = rstTableName.RecordCount
  4.  
  5.             rstTableName.MoveFirst
  6.  
Jim
May 27 '14 #3
Hi Jim

Firstly thank you very much for the quick response
You are correct it dies on the the line where i set the dbs variable

I use that variable to update the query (which has been created in the Access DB) with the SQL
Expand|Select|Wrap|Line Numbers
  1. ishare_query.SQL = "SELECT HAWB, [Orig Ctr], [Dest Ctr], True Value], [True CUR], [Created By], " & _ 
  2.  
  3.         "Undervalued.Created INTO [1-T_ISHARE INFO]FROM Undervalued WHERE (((Created)>=#" & strDateLimit & "#));" 
  4.  
The original is the same except the date is different. I run it once a week and the strDateLimit is the only thing that changes

I have also moved the code around so this is the first function being called and as a result the first use of the DAO

Here is the SQL in the Query

Expand|Select|Wrap|Line Numbers
  1. SELECT Undervalued.HAWB, [Orig Ctr], [Dest Ctr], [True Value], [True CUR], [Created By], Created INTO [1-T_ISHARE INFO]
  2. FROM Undervalued
  3. WHERE (((Created)>=#12/27/2013#));
May 27 '14 #4
jimatqsi
1,271 Expert 1GB
Harry,
I'm not sure I understand. Line 65 cannot work because line 63 is commented out. Are you saying when you remove ' from line 63 the program fails on that line? What is the nature of the failure?

Remove line 39 for now. When it is time to put it back in you'll want to put immediately before the one line that you know you don't want any messages from, and reverse it immediately after that one line. Eliminating messages from the entire code gets in the way of debugging it.

I don't understand why line 59 references query "Q1 Retrieve All Information From ISHARE" but line 73 references query "Q1". What is the relationship between them? And what is query "Q2"?

Jim
May 27 '14 #5
Hi Jim

Sorry, I was attempting to anonomize the code while in a meeting...multi-tasking :)
I have updated it in the original question

Basically Q1 takes messy information from a sharepoint list
Q2 depuplicates that list

Due to performance issues, Q1 was set up so that it only took the previous couple of months from the sharepoint list

It is then loaded from the table 2-DEDUP into an array for further processing down the code

Apologies again for the ambiguity. I appreciate all feedback as i have a feeling this problem will come up in other projects
May 27 '14 #6
jimatqsi
1,271 Expert 1GB
Harry, it's a really bad idea to change your posts after getting feedback. It means subsequent readers can't follow the conversation and might not be able to learn what you learned during the discussion.

At this point I am not sure what problem we're trying to solve. Is the error "the database has been locked by the admin" still a problem? Is "the Object Variable or With block not set" still a problem?

I noticed your reposted code still is not moving to the end of the recordset before getting the record count.

Also, what is the name of the database this code is running in? Is it C:\Users\User\Desktop\DB1.accdb? If so, you should use
Expand|Select|Wrap|Line Numbers
  1. set dbs = currentdb 
instead of
Expand|Select|Wrap|Line Numbers
  1. set dbs = OpenDatabase("C:\Users\User\Desktop\DB1.accdb")
That alone might solve your problem with the locked database.

Jim
May 27 '14 #7
Hi Jim

Apologies for all the confusion
Im running it now with the changes to Set DBS (it takes several hours but so far looks good)

Can you tell me setting it to the current DB is different from simply specifying the full path of the DB

Will this work for example if i load the DB from a network drive

Im interested in understand the why as well as the answer

Again, thank you very much for your help. It has been a tremendous learning experience
May 28 '14 #8
jimatqsi
1,271 Expert 1GB
Harry,
When you specified the full path to the DB, apparently Access was opening a new, separate channel to the database. That is, it looked like two separate users were accessing the DB. Therefore, you were set up to make a conflict between you and yourself when any resource was locked by either instance of yourself.

If you are going to load the DB from a network drive it shouldn't make any difference unless you plan to allow multiple users to access simultaneously. In that case, only data should be in the remote database and each user should have their own copy of the front-end on their local machine and you may have to build some logic to coordinate user activities so one user is not rebuilding a table that another user is using at that moment.

Glad to know you may have gotten over the hurdle on this one.

Jim
May 28 '14 #9
NeoPa
32,556 Expert Mod 16PB
I've changed the Best Answer as post #8 wasn't.
May 29 '14 #10

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

Similar topics

1
by: Perttu Pulkkinen | last post by:
Hi all freaks! I have been thinking hard, what would be good solution for a straight-forward content management. I want to forget polls and forms etc.. and concentrate first only on different...
0
by: Chris Back | last post by:
Hi all, We are having a tough time tracking down a problem with my MySQL database. The version is 3.23.58 running as the backend for Request Tracker (rt2) by Best Practical. Occasionally...
1
by: swingingming | last post by:
Hi, I used DAO and it works fine. But when I try to use ADO, it says the database is locked by the user. How can I get around this? Which property should I set? Thanks. ming
10
by: Daniel | last post by:
How can i break my access 2000 VBA project password ? it has been locked and i forget the password. Pls help. Thanks. Daniel
0
by: Tommy B | last post by:
I'm currently working on a casino script for an IRC bot. I was going to make a flat file database, but I decided to make it sqlite after some suggestions. I'm using pysqlite. ...
6
by: vabsjava | last post by:
HI! everybody I am giong in all directions of ASP being a beginner. I am getting right with connecting asp page. I am getting right with extracting the data from database using "request.form" but...
4
by: Trisk | last post by:
When I have gone to compact an acces database I get an error message saying that a user is still using it, but all (2) applications had been closed (but one may not have closed properly). I have done...
11
ollyb303
by: ollyb303 | last post by:
Hi, I have a problem with a multi-user db in Access 2000. The db is for logging calls to my company and will be used by up to 30 people, though currently around 10 are using it. I have split...
2
by: gangac | last post by:
I am currently working on an ms access application for a large insurance company which generates reports for the user after the user inputs/select some data.... Unfortunately the application has...
10
by: ncsubvet | last post by:
I have a database .mdb that was created by someone who no longer works here. I have been tasked with creating a new database for our needs, but I need to retrieve some info from the old database. I...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.