ClimoC
Well-known Member
- Joined
- Aug 21, 2009
- Messages
- 584
Howdy
I have an Excel Workbook with userforms, pivottables and the like. The backend is an Access db (accdb), with connection through ADODB
Everything seems to work beautifully, except when I'm adding a new record.
Here's the startup connection:
This is a relatively new approach for me (I didn't realise I could use connected recordsets, previously in other programmes I kept everything separate as disconnected recordsets, then relied on worksheet_change events to fire SQL queries to update the database, and refresh the tableview every x seconds.)
When I try and add a new record to multiple tables, the first updatebatch method works fine as it is. The others don't work about 60-70% of the time (record is not inserted to the other tables)
There are a couple of requeries in there for the FinRS connection, because it seems to bring the success rate up from 0% to about 30%.
I've noticed it's also more likely to work if the database is open in Access whilst interaction occurs with the Excel-housed userforms.
Are there settings in Access/The connection parameters that can make Access execute all changes in the cache instantly? Nowhere will people be updating multiple records at any one time - they select the record they want to edit, type in the fields, and move on.
Are my problems even cache based? Is it the order I do things in? Settings in the Finance table (FinRS)?
Could really do with some help, because it hinders the project if adding a new record doesn't always work
Thanks
C
I have an Excel Workbook with userforms, pivottables and the like. The backend is an Access db (accdb), with connection through ADODB
Everything seems to work beautifully, except when I'm adding a new record.
Here's the startup connection:
Code:
Public Function TestBatchUpdate()
Dim strConn As String, strFileSpec As String
Set ConnLink = New ADODB.Connection
strFileSpec = ThisWorkbook.Path & "\Io.accdb"
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFileSpec & ";Persist Security Info=False;"
With ConnLink
.CursorLocation = adUseClient
.CommandTimeout = 0
.Open strConn
End With
Set FinRS = New ADODB.Recordset
Set SchRS = New ADODB.Recordset
Set ProRS = New ADODB.Recordset
Set FisQuLU = New ADODB.Recordset
Set FisYeLU = New ADODB.Recordset
Set FisPeLU = New ADODB.Recordset
Set Users = New ADODB.Recordset
ProRS.Open "Programmes", ConnLink, adOpenStatic, adLockBatchOptimistic
SchRS.Open "Scheduling", ConnLink, adOpenStatic, adLockBatchOptimistic
FinRS.Open "Finance", ConnLink, adOpenStatic, adLockBatchOptimistic
FisQuLU.Open "Fiscal_Quarter_Lookup", ConnLink, adOpenStatic, adLockBatchOptimistic
FisYeLU.Open "Fiscal_Year_Lookup", ConnLink, adOpenStatic, adLockBatchOptimistic
FisPeLU.Open "Fiscal_Period_Lookup", ConnLink, adOpenStatic, adLockBatchOptimistic
Users.Open "Users", ConnLink, adOpenStatic, adLockBatchOptimistic
End Function
This is a relatively new approach for me (I didn't realise I could use connected recordsets, previously in other programmes I kept everything separate as disconnected recordsets, then relied on worksheet_change events to fire SQL queries to update the database, and refresh the tableview every x seconds.)
When I try and add a new record to multiple tables, the first updatebatch method works fine as it is. The others don't work about 60-70% of the time (record is not inserted to the other tables)
Code:
With ProRS
.Filter = adFilterNone
.MoveFirst
.AddNew Array("Series_Name", "Series_Number", "Run_Number"), Array(Trim(ADDSeriesName.Value), CLng(ADDSeriesNo.Value), CLng(ADDRunNo.Value))
.Fields("Series_ID").Value = 0
.UpdateBatch
S_ID = .Fields("PK").Value
.Fields("Series_ID").Value = S_ID
.UpdateBatch
End With
With FinRS
.AddNew Array("Series_ID", "Schedule_ID", "Amort_Policy"), Array(S_ID, 0, 0)
.UpdateBatch
.Requery
End With
ProRS.Requery
FinRS.Requery
There are a couple of requeries in there for the FinRS connection, because it seems to bring the success rate up from 0% to about 30%.
I've noticed it's also more likely to work if the database is open in Access whilst interaction occurs with the Excel-housed userforms.
Are there settings in Access/The connection parameters that can make Access execute all changes in the cache instantly? Nowhere will people be updating multiple records at any one time - they select the record they want to edit, type in the fields, and move on.
Are my problems even cache based? Is it the order I do things in? Settings in the Finance table (FinRS)?
Could really do with some help, because it hinders the project if adding a new record doesn't always work
Thanks
C