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(s trqueryname), 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
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
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(s trqueryname), 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
Code:
Public Function Retrieve_Sharepoint_Records() As Variant
On Error GoTo ErrorHandler
Dim dbs As DAO.Database
Dim ishare_query As DAO.QueryDef
Dim rstTableName As DAO.Recordset 'Your table
Dim MyArray() As Variant 'Your dynamic array
Dim intArraySize As Integer 'The size of your array
Dim iCounter As Integer 'Index of the array
DoCmd.SetWarnings False
strDateLimit = Format(DateAdd("m", -5, Date), "dd-mm-yyyy")
strqueryname = "Q1"
Set dbs = OpenDatabase("C:\Users\User\Desktop\DB1.accdb")
Set ishare_query = dbs.QueryDefs(strqueryname)
ishare_query.SQL = "SELECT HAWB, Orig Ctr], Dest Ctr], True Value], Undervalued.[True CUR], [Created By], " & _
"Undervalued.Created INTO [1-T_ISHARE INFO]FROM Undervalued WHERE (((Created)>=#" & strDateLimit & "#));"
DoCmd.OpenQuery "Q1", acViewNormal, acEdit
DoCmd.OpenQuery "Q2", acViewNormal, acEdit
' Table 2 is generated from the query Q2
Set rstTableName = CurrentDb.OpenRecordset("2-DEDUP")
If Not rstTableName.EOF Then
rstTableName.MoveFirst
rstTableName.MoveFirst
numrecs = rstTableName.RecordCount
'use "GetRows" method to assign to an array
MyArray = rstTableName.GetRows(numrecs)
End If
Retrieve_Sharepoint_Records = MyArray
Debug.Print "***Ishare Records Retrieved " & numrecs & " Rows***"
ErrorHandler:
DoCmd.SetWarnings True
If (Len(Err.Description) > 0) Then
MsgBox (Err.Description)
End If
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
Comment