Thurs 16th - Cracked it partly.... plse see end of thread...
Access2007, .mdb file, local machine
I seem to be having difficulties refreshing a form's recordset. I populate the ADO based form by building an SQL string and then applying it as the source to an ADO recordset....
OnOpen event
Code:
SQLLINE = "SELECT * FROM Addresses WHERE Deleted=False"
Set Frm_CnnADO = CurrentProject.AccessConnection
Set Frm_RstADO = New ADODB.Recordset
With Frm_RstADO
Set .ActiveConnection = Frm_CnnADO
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.Open
End With
Set Me.Form.Recordset = Frm_RstADO
Set Frm_RstADO = Nothing
Set Frm_CnnADO = Nothing
I understood that, with ADO, the equivalent of a requery was just to reset the recordset to itself? i.e.
Set me.form.recordset = me.form.recordset
You'll notice the SQL has a "WHERE Deleted=False". By way of experiment, I loaded my form then went into the table and unset a ton of Deleted flags. I then "refreshed" the form's recordset (as per above). However none of the un-deleted Addresses appeared in the form?
I have tried adOpenKeySet, adOpenDynamic and adOpenStatic cursor types but none pick up he changed records? Also, I notice that if I msgbox "me.form.Recordset.CursorType", Access always reports it as 3 which is adOpenStatic no matter which cursortype I specify.... can it get anymore confusing?
I know I can set the recordset=nothing and then rebuild it (as per code in the Open event above) but this unloads and reloads all it's subforms... takes an age.
I'm stumped.... worked on this all day... I've tried combinations of:-
1. changing cursortypes
2. Leaving the Frm_CnnAdo / setting Frm_CnnADO to nothing (durng the open event)
3. set me.form.recordset = me.form.recordset
4. me.form.recordset.requery
5. me.form.recordset.resync
I was hoping to be able to see records added/edited/deleted (by other users) by 'requerying' the Rs rather than setting the Form.RS = Nothing and then Adding it back.
The latter unloads/reloads all subforms - takes an age and, since they are not master/child linked, is a waste.
Can it really be this difficult for a database product to see database records??
That line results in a disconnected recordset. It is one of the features of ADODB and is used to reduce the connection load on the server. It is very useful with ASP where there may be hundreds of users connecting from a webpage.
The recordset can be edited on the client and then reconnected to the server. However it is usually left connected if that feature is not required.
Obviously it cannot show other users changes while it is disconnected.
My form-open now leaves the Cnn and RS in place. I also have used the Dynamic cursor type (although it still reports itself as type 3)... so ...
Code:
SQLLine = "blah blah"
Set Frm_CnnADO = CurrentProject.AccessConnection
Set Frm_RstADO = New ADODB.Recordset
With Frm_RstADO
Set .ActiveConnection = Frm_CnnADO
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.Open
End With
Set Me.Form.Recordset = Frm_RstADO
' Set Frm_RstADO = Nothing 'commented out
' Set Frm_CnnADO = Nothing 'commented out
Having amended a record in the table itself, I then reset the form's (it's actually a subform) RS with :-
Code:
Set Me.My_subform.Form.Recordset = Me.My_subform.Form.Recordset
Sadly, no sign of the amended record. To be certain I close and re-open the form and the amended record is correctly displayed.
I have had varying results with the use of CurrentProject.AccessConnection vs CurrentProject.Connection ... one of which would not let me add records with .addnew .. I can't remember which.. maybe it's that that's the problem... I'm a little paranoid about changing all that though....
Interesting point about disconnected RS's so I also tried a me.my_subform.form.recordset.resync .... still no joy..
Just one further thing I looked at was the form's own properties such as RecordSetType=Dynaset ... but I guess these are there for DAO and are overridden by the ADO connection anyway?
Client side cursors always produce a a Static Cursor no matter what you define.
This is the actual problem. You need a Dynamic Cursor (adOpenDynamic) to see new records or a keyset (adOpenKeyset) if you just want to see the edits of existing records.
Change the CursorLocation to adUseServer.
I have had varying results with the use of CurrentProject.AccessConnection vs CurrentProject.Connection ... one of which would not let me add records with .addnew
Currentproject.AccessConnection is required for form recordsets to be updateable.
I looked at was the form's own properties such as RecordSetType=Dynaset ... but I guess these are there for DAO and are overridden by the ADO connection anyway?
Oh... I see ...thanks for the info... it really is utterly bewildering... here's the results of some testing I've done today... I've tried to summarise the results at the bottom of the thread.
Tests - Preamble:
a) Addresses table has a 'Deleted' column - The SQL for the RS has "WHERE Deleted=False" statement.
b) Addresses table has a "Name" column - A text, user supplied, field describing the address e.g. Fred's Home Address.
Tests -
a) Open Addresses form with varying RS Open params as below
b) Alter "Name" column of one or more records in table
c) Set / Unset Deleted columns of one or more records in table
d) record results from:-
i) Msgbox ENUMs for RS params
ii) Use- me.form.recordset.Resync
iii) Use- Set me.form.recordset = me.form.recordset
iv) Use - me.form.recordset.Requery
To make these a little more readable, I've indicated in bold where relevant bits have been changed between tests...
------------------------------------------------------------
TEST 1.
------------------------------------------------------------
With Open Parms
Code:
Set Frm_CnnADO = [B]CurrentProject.AccessConnection[/B]
Set Frm_RstADO = New ADODB.Recordset
With Frm_RstADO
Set .ActiveConnection = Frm_CnnADO
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = [B]adOpenDynamic[/B]
.CursorLocation = [B]adUseServer[/B]
.Open
End With
Set Me.Form.Recordset = Frm_RstADO
[B]Set Frm_RstADO = Nothing[/B]
[B]Set Frm_CnnADO = Nothing[/B]
Results:
--------
i) Enums etc ActiveConnection=Provider=Microsoft.Access.OLEDB.10.0;Persist Security Info=False;Data Source=C:\Shared_Network_MOWKS\Addresses_Test_v471.mdb;User ID=Admin;Data Provider=Microsoft.ACE.OLEDB.12.0
CursorLocation=3
CursorType=3
ii) Resync -
Edits to Names - Changes displayed.
Resets of Deleted Flag - No changes displayed.
iii) Set Rs=Rs -
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
iv) Requery
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
Note: when called twice all boxes in form display "#Name?" .
------------------------------------------------
TEST 2.
------------------------------------------------
With Open Parms
Code:
Set Frm_CnnADO = CurrentProject.AccessConnection
Set Frm_RstADO = New ADODB.Recordset
With Frm_RstADO
Set .ActiveConnection = Frm_CnnADO
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = adOpenDynamic
.CursorLocation = adUseServer
.Open
End With
Set Me.Form.Recordset = Frm_RstADO
Set Frm_RstADO = Nothing
[B]' Set Frm_CnnADO = Nothing 'commented out[/B]
i) Enums etc
ActiveConnection=Provider=Microsoft.Access.OLEDB.10.0;Persist Security Info=False;Data Source=C:\Shared_Network_MOWKS\Addresses_Test_v471.mdb;User ID=Admin;Data Provider=Microsoft.ACE.OLEDB.12.0
CursorLocation=3
CursorType=3
ii) Resync -
Edits to Names - Changes displayed.
Resets of Deleted Flag - No changes displayed.
iii) Set Rs=Rs -
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
iv) Requery
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
Note: when called twice all boxes in form display "#Name?" .
-----------------------------------------------------------
TEST 3.
-----------------------------------------------------------
With Open Parms
Code:
Set Frm_CnnADO = CurrentProject.AccessConnection
Set Frm_RstADO = New ADODB.Recordset
With Frm_RstADO
Set .ActiveConnection = Frm_CnnADO
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = adOpenDynamic
.CursorLocation = adUseServer
.Open
End With
Set Me.Form.Recordset = Frm_RstADO
' [B]Set Frm_RstADO = Nothing 'commented out[/B]
[B]' Set Frm_CnnADO = Nothing 'commented out[/B]
i) Enums etc
ActiveConnection=Provider=Microsoft.Access.OLEDB.10.0;Persist Security Info=False;Data Source=C:\Shared_Network_MOWKS\Addresses_Test_v471.mdb;User ID=Admin;Data Provider=Microsoft.ACE.OLEDB.12.0
CursorLocation=3
CursorType=3
ii) Resync -
Edits to Names - Changes displayed.
Resets of Deleted Flag - No changes displayed.
iii) Set Rs=Rs -
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
iv) Requery
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
Note: when called twice all boxes in form display "#Name?" .
-----------------------------------------------------------
TEST 4.
-----------------------------------------------------------
With Open Parms
Code:
Set Frm_CnnADO = CurrentProject.AccessConnection
Set Frm_RstADO = New ADODB.Recordset
With Frm_RstADO
Set .ActiveConnection = Frm_CnnADO
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = adOpenDynamic
.CursorLocation = [B]adUseClient[/B]
.Open
End With
Set Me.Form.Recordset = Frm_RstADO
Set Frm_RstADO = Nothing
Set Frm_CnnADO = Nothing
i) Enums etc
ActiveConnection=Provider=Microsoft.Access.OLEDB.10.0;Persist Security Info=False;Data Source=C:\Shared_Network_MOWKS\Addresses_Test_v471.mdb;User ID=Admin;Data Provider=Microsoft.ACE.OLEDB.12.0
CursorLocation=3
CursorType=3
ii) Resync -
Edits to Names - Changes displayed.
Resets of Deleted Flag - No changes displayed.
iii) Set Rs=Rs -
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
iv) Requery
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
Note: when called twice all boxes in form display "#Name?" .
------------------------------------------------------------
TEST 5.
------------------------------------------------------------
With Open Parms
Code:
Set Frm_CnnADO = CurrentProject.AccessConnection
Set Frm_RstADO = New ADODB.Recordset
With Frm_RstADO
Set .ActiveConnection = Frm_CnnADO
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.Open
End With
Set Me.Form.Recordset = Frm_RstADO
Set Frm_RstADO = Nothing
[B]' Set Frm_CnnADO = Nothing 'commented out[/B]
i) Enums etc
ActiveConnection=Provider=Microsoft.Access.OLEDB.10.0;Persist Security Info=False;Data Source=C:\Shared_Network_MOWKS\Addresses_Test_v471.mdb;User ID=Admin;Data Provider=Microsoft.ACE.OLEDB.12.0
CursorLocation=3
CursorType=3
ii) Resync -
Edits to Names - Changes displayed.
Resets of Deleted Flag - No changes displayed.
iii) Set Rs=Rs -
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
iv) Requery
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
Note: when called twice all boxes in form display "#Name?" .
------------------------------------------------------------
TEST 6.
------------------------------------------------------------
With Open Parms
Code:
Set Frm_CnnADO = CurrentProject.AccessConnection
Set Frm_RstADO = New ADODB.Recordset
With Frm_RstADO
Set .ActiveConnection = Frm_CnnADO
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.Open
End With
Set Me.Form.Recordset = Frm_RstADO
' [B]Set Frm_RstADO = Nothing[/B] [B]'commented out[/B]
[B]' Set Frm_CnnADO = Nothing 'commented out[/B]
i) Enums etc
ActiveConnection=Provider=Microsoft.Access.OLEDB.10.0;Persist Security Info=False;Data Source=C:\Shared_Network_MOWKS\Addresses_Test_v471.mdb;User ID=Admin;Data Provider=Microsoft.ACE.OLEDB.12.0
CursorLocation=3
CursorType=3
ii) Resync -
Edits to Names - Changes displayed.
Resets of Deleted Flag - No changes displayed.
iii) Set Rs=Rs -
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
iv) Requery
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
Note: when called twice all boxes in form display "#Name?" .
--------------------------------------------------------
TEST 7.
-------------------------------------------------------
With Open Parms
Code:
Set Frm_CnnADO = [B]CurrentProject.Connection[/B]
Set Frm_RstADO = New ADODB.Recordset
With Frm_RstADO
Set .ActiveConnection = Frm_CnnADO
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = adOpenDynamic
.CursorLocation = [B]adUseServer[/B]
.Open
End With
Set Me.Form.Recordset = Frm_RstADO
Set Frm_RstADO = Nothing
Set Frm_CnnADO = Nothing
RESULTS: Crashes Access - "Not a valid recordset property"
------------------------------------------------------
TEST 8.
------------------------------------------------------
With Open Parms
Code:
Set Frm_CnnADO = CurrentProject.Connection
Set Frm_RstADO = New ADODB.Recordset
With Frm_RstADO
Set .ActiveConnection = Frm_CnnADO
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = adOpenDynamic
.CursorLocation = [B]adUseClient[/B]
.Open
End With
Set Me.Form.Recordset = Frm_RstADO
Set Frm_RstADO = Nothing
Set Frm_CnnADO = Nothing
i) Enums etc
ActiveConnection=Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Shared_Network_MOWKS\Addresses_Test_v471.mdb;Mode=Share Deny None;Extended Properties="";Jet OLEDB:System database=C:\Documents and Settings\grahame.peet.CS\Application Data\Microsoft\Access\System2.mdw;Jet OLEDB:Registry Path=Software\Microsoft\Office\12.0\Access\Access Connectivity Engine;Jet OLEDBatabase Password="";Jet OLEDB:Engine Type=5;Jet OLEDBatabase Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDBon't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=True
CursorLocation=3
CursorType=3
ii) Resync -
Edits to Names - Changes displayed.
Resets of Deleted Flag - No changes displayed.
iii) Set Rs=Rs -
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
iv) Requery
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
Note: when called twice all boxes in form display "#Name?" .
-----------------------------------------------------
TEST 9.
-----------------------------------------------------
With Open Parms
Code:
Set Frm_CnnADO = CurrentProject.Connection
Set Frm_RstADO = New ADODB.Recordset
With Frm_RstADO
Set .ActiveConnection = Frm_CnnADO
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.Open
End With
Set Me.Form.Recordset = Frm_RstADO
Set Frm_RstADO = Nothing
[B]' Set Frm_CnnADO = Nothing[/B] [B]'commented out[/B]
i) Enums etc
ActiveConnection=Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Shared_Network_MOWKS\Addresses_Test_v471.mdb;Mode=Share Deny None;Extended Properties="";Jet OLEDB:System database=C:\Documents and Settings\grahame.peet.CS\Application Data\Microsoft\Access\System2.mdw;Jet OLEDB:Registry Path=Software\Microsoft\Office\12.0\Access\Access Connectivity Engine;Jet OLEDBatabase Password="";Jet OLEDB:Engine Type=5;Jet OLEDBatabase Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDBon't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=True
CursorLocation=3
CursorType=3
ii) Resync -
Edits to Names - Changes displayed.
Resets of Deleted Flag - No changes displayed.
iii) Set Rs=Rs -
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
iv) Requery
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
Note: when called twice all boxes in form display "#Name?" .
---------------------------------------------------------
TEST 10.
---------------------------------------------------------
With Open Parms
Code:
Set Frm_CnnADO = CurrentProject.Connection
Set Frm_RstADO = New ADODB.Recordset
With Frm_RstADO
Set .ActiveConnection = Frm_CnnADO
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.Open
End With
Set Me.Form.Recordset = Frm_RstADO
[B]' Set Frm_RstADO = Nothing 'commented out[/B]
[B]' Set Frm_CnnADO = Nothing[/B] [B]'commented out[/B]
i) Enums etc
ActiveConnection=Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Shared_Network_MOWKS\Addresses_Test_v471.mdb;Mode=Share Deny None;Extended Properties="";Jet OLEDB:System database=C:\Documents and Settings\grahame.peet.CS\Application Data\Microsoft\Access\System2.mdw;Jet OLEDB:Registry Path=Software\Microsoft\Office\12.0\Access\Access Connectivity Engine;Jet OLEDBatabase Password="";Jet OLEDB:Engine Type=5;Jet OLEDBatabase Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDBon't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=True
CursorLocation=3
CursorType=3
ii) Resync -
Edits to Names - Changes displayed.
Resets of Deleted Flag - No changes displayed.
iii) Set Rs=Rs -
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
iv) Requery
Edits to Names - No changes displayed.
Resets of Deleted Flag - No changes displayed.
Note: when called twice all boxes in form display "#Name?" .
----------------------------------------------------------
END OF TESTS
----------------------------------------------------------
I wish this had helped... but i'm even more confused...
.Resync produces some results (which conflict with the reported cursortype - see beow)
.Set RS=RS produces no results
.Requery - produces no reults (except to blow the form to pieces) despite the description of requery in W3C
I guess the first thing to note is that Cursorlocation and Cursortype always report themselves as 3 ???
CursorLocation 3 = "Uses a client-side cursor supplied by a local cursor library. For backward compatibility, the synonym adUseClientBatch is also supported"
CursorType 3 = "Uses a static cursor. A static copy of a set of records that you can use to find data or generate reports. Additions, changes, or deletions by other users are not visible."
Here's how I got them...
Msgbox "CursorLocation=" & Me.My_subform.Form.Recordset.CursorLocation
Msgbox "CursorType=" & Me.My_subform.Form.Recordset.CursorType
If it is a CursorType of 3, how did Resync pick up edited names??
Access - or rather inAccess can be mightly difficult to understand.....
The only reliable way I've found to pick up changes is to re-load the form (and as a consequence all subforms). Rather drastic one might say.
Well I've got part of it fixed... the trick was to use this combination....
me.my_subform.form.recordset.requery
set me.my_subform.form.recordset = me.my_subform.form.recordset
Without doing an unload/load of the subform (only seems to fire the current event), this correctly displays edits to records and adds/removes records in the form's RS in accordance with their deleted column. It does not seem to worry about adUseClient/adUseServer.
At present, of course, it's the same Access (admin) user updating the raw tables as well as using the form. Whether this functionality will still work with other user's updates remains to be seen.
Unfortuantely, calling the same two commands against my main form still goes off and reloads all the subforms.... and this is what I've being trying to avoid from the outset ...
My main and subform both look at the same set of records (i.e. they use the same SQLstring in their ADODB.Recordset.Source). They are not master/child linked but are sync'd using bookmarks. I have custom buttons sited on my mainform and in this way I can display all address records in the subform (in datasheet view) and still have access to my buttons..... my main-form is really just the 'glue' between the 'primary' subform and several other subforms. So if I change my primary-subform I have to change my main.... I'm gussing I'm just going to have to put up with it unless one of you Access gurus out there can think of a more efficient way?
Unfortuantely, calling the same two commands against my main form still goes off and reloads all the subforms.... and this is what I've being trying to avoid from the outset ...
No, none of the forms/subforms share a recordset as such (I didn't even know that was possible?).
The main and 1st subform (I call it the 'primary' subform) use the same SQL string but which is then used as the source for their own individual RSs.
The remaining subforms present data from tables associated with that of the main form. There are no Master/Child links anywhere because these are all ADODB based forms. To replicate Master/Child links these subforms are filtered during the main form Current_Event.
All works well except for seeing other users' changes. This can be acheived but only by reloading the main form... (and the consequent reload of all subforms). I assumed there would be a simple method to 'refresh' the data from the tabls into the ADODB RSs without all these form reloads?
Okay. I'm beginning to understand. Interesting about all of your tests that no matter what you did the cursor was a static cursor and the location was client side. What can you say about this database? Anything unusual about it or the data connections? What kind of changing information do you users need to see on these tabs?