You must use the dbSeeChanges option with OpenRecordset when accessing a sql server (1 Viewer)

johnkrytus

Registered User.
Local time
Today, 06:10
Joined
Mar 7, 2013
Messages
91
We just converted our database from postgres to SQL Server. This error appears to be all over our code.

You must use the dbSeeChanges option with OpenRecordset when accessing a sql server


I am only a novice level coder and the guy who often helps me just left on vacation. Any help would be appreciated greatly.

Apparently it dislikes this line of code:
Code:
Public Sub clearFilterForBucket(bucket_name As String, filter_id As Integer)
  CurrentDb.Execute ("delete from filter_actions where filter_id= " & filter_id & " AND action= '" & bucket_name & "'")
End Sub

Which is called from here:
Code:
Private Sub b_send_Click()
   Dim title_id As Integer
   Dim rstFilters As DAO.Recordset
   Dim rstPeople As DAO.Recordset
   Dim filterQry As String
   Dim answer As String
   Dim newFilter As DAO.Recordset
   Dim ctrl_bucket_name As String
   Dim maxSize As Integer
   maxSize = 100 '--how many records we can add to a filter at once
   
   If IsNull(ctrl_company_id) Then
     MsgBox ("You did not select a company")
   ElseIf IsNull(ctrl_company_titles) Then
     MsgBox ("You did not select a Title")
   ElseIf IsNull(ctrl_filtername) Then
     MsgBox ("You did not select a filter")
   Else
     Set rstPeople = [Forms]![Search_Filter_People]![filter_people_results].[Form].Recordset
     
     If rstPeople.RecordCount > maxSize Then
       MsgBox ("You are trying to add more than " & maxSize & " records to a filter. Please use a smaller data set")
     Else
       Call clearFilterForBucket("added", Forms.Search_Filter_People.Form.ctrl_filtername.Value)
       Call addPeopleToFilter(rstPeople, Forms.Search_Filter_People.Form.ctrl_filtername.Value)
     
       Me.filter_people_results.SourceObject = "filter_people_results"
       ctrl_bucket_name = "added"
     
       Me.filter_people_results.Form.RecordSource = "select (FirstName + ' ' + LastName) as fullname, * from people where EmployeeID IN ( select person_id from filter_actions where filter_id =" & ctrl_filtername & " and action='" & ctrl_bucket_name & "') order by LastCnct desc"
       Me.filter_people_results.Form.Requery
       update_bucketcounts
     End If
   End If
End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:10
Joined
Aug 30, 2003
Messages
36,125
This is that rare error that tells you exactly what is wrong.

Db.Execute "delete from filter_actions where filter_id= " & filter_id & " AND action= '" & bucket_name & "'", dbSeeChanges
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 11:10
Joined
Sep 12, 2006
Messages
15,656
generally this. (there might be an extra comma before the dbseechanges)

db.openrecordset("somequery"),dbseechanges
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:10
Joined
Aug 30, 2003
Messages
36,125
For a recordset:

Set rs = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 11:10
Joined
Sep 12, 2006
Messages
15,656
thanks paul - often hard to do things you rarely do from memory.

john - you will need to convert every usage of recordsets in your app to use dbseechanges. bit of a pain.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:10
Joined
Aug 30, 2003
Messages
36,125
If memory serves, it's actually only necessary if the SQL Server table has an Identity (autonumber) field. It doesn't hurt to have it everywhere though, in case the source changes (as happened here).
 

johnkrytus

Registered User.
Local time
Today, 06:10
Joined
Mar 7, 2013
Messages
91
This is an "invalid operation"

From what I understand of this it's not what I want to do anyways... I just want the query to run. I don't want to assign a value to rs. ....do I???? Sorry. I know I'm in over my head here, but that doesnt get me off the hook for needing to solve it.

Code:
Public Sub clearFilterForBucket(bucket_name As String, filter_id As Integer)
  Dim rs As DAO.Recordset
  Set rs = CurrentDb.OpenRecordset("delete from filter_actions where filter_id= " & filter_id & " AND action= '" & bucket_name & "'", dbOpenDynaset, dbSeeChanges)
End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:10
Joined
Aug 30, 2003
Messages
36,125
Did you try what I posted in post 2?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:10
Joined
Aug 30, 2003
Messages
36,125
Did you change back to CurrentDb? Somehow in my copying and pasting that got changed. should be:

CurrentDb.Execute "delete from filter_actions where filter_id= " & filter_id & " AND action= '" & bucket_name & "'", dbSeeChanges

I use a variable for the SQL, but it should work either way. This is from a production db:

CurrentDb.Execute strSQL, dbSeeChanges
 

johnkrytus

Registered User.
Local time
Today, 06:10
Joined
Mar 7, 2013
Messages
91
It works!! I don't know what I'd do without this forum! You guys rock!

Code:
Public Sub clearFilterForBucket(bucket_name As String, filter_id As Integer)
  Currentdb.Execute "delete from filter_actions where filter_id= " & filter_id & " AND action= '" & bucket_name & "'", dbSeeChanges
End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:10
Joined
Aug 30, 2003
Messages
36,125
Happy to help!
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 11:10
Joined
Sep 12, 2006
Messages
15,656
as an aside, now you mention the issue of identity columns ...

I have been really struggling with SQL server, trying to insert data to tables with autonumber fields. I "set identity insert" on, but the pass through query won't take it off again.

I think perhaps you have to use a different connection to take it off. Total pain. What I am having to do, is exit and restart access, and then the next "set identity insert" works
 

Minty

AWF VIP
Local time
Today, 11:10
Joined
Jul 26, 2013
Messages
10,371
I "set identity insert" on, but the pass through query won't take it off again.

SET IDENTITY_INSERT tablenameWithIdentitySetOn OFF is the correct syntax, I'm intrigued as to why you would be inserting values into an identity field.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 11:10
Joined
Sep 12, 2006
Messages
15,656
SET IDENTITY_INSERT tablenameWithIdentitySetOn OFF is the correct syntax, I'm intrigued as to why you would be inserting values into an identity field.

I'm upsizing an access dbs to Sql server. Some tables have autonumbers and I can't use any wizard. I have to do it a table at a time.
 

Users who are viewing this thread

Top Bottom