Solved

cannot edit dao.recordset

Posted on 2014-09-03
3
158 Views
Last Modified: 2014-09-03
I have added a small section onto a previous function but when it tries to edit it gives error 3027, cannot update.

Not sure why.

Private Function BtnPrepareData_Click(Clien<wbr ></wbr>tName As String, ManfName As String, ModelName As String)
Dim QryName As String
Dim countrecords As Long

Dim sqltext As String
Dim sqlAlternate As String
Dim StrTable As String
Dim Db As DAO.Database
Set Db = CurrentDb()
Dim qdfNew As DAO.QueryDef
Dim RstCUREmpty As DAO.Recordset
StrTable = "ClientWordGroups"
QryName = "Qryupdateunwantedfield"

DoCmd.SetWarnings False
DoCmd.OpenQuery "QryReplaceQuotes"

Dim SqltoUse As Boolean

SqltoUse = InAutoRangeList(ModelName)<wbr ></wbr>
If SqltoUse = False Then

sqltext = "UPDATE ClientWordGroups SET ClientWordGroups.Concatena<wbr ></wbr>tedUnwante<wbr ></wbr>dRemoval =" _
& " replacemulti([concatenated<wbr ></wbr>],'" & ClientName & "','" & ManfName & "')" _
& " WHERE (((ClientWordGroups.Client<wbr ></wbr>)='" & ClientName & "') AND ((ClientWordGroups.MarqueA<wbr ></wbr>lias)='" & ManfName & "') AND ((ClientWordGroups.concate<wbr ></wbr>nated) Like '*" & ModelName & "*'));" _




Else

sqltext = "UPDATE ClientWordGroups SET ClientWordGroups.Concatena<wbr ></wbr>tedUnwante<wbr ></wbr>dRemoval =" _
& " replacemulti([concatenated<wbr ></wbr>],'" & ClientName & "','" & ManfName & "')" _
& " WHERE (((ClientWordGroups.Client<wbr ></wbr>)='" & ClientName & "') AND ((ClientWordGroups.MarqueA<wbr ></wbr>lias)='" & ManfName & "') AND ((ClientWordGroups.groups)<wbr ></wbr> Like '*" & ModelName & "*'));" _





End If

Debug.Print sqltext


If IsTableQuery("", QryName) = True Then

    DoCmd.DeleteObject acQuery, QryName
End If


Set qdfNew = CurrentDb.CreateQueryDef(Q<wbr ></wbr>ryName, sqltext)
qdfNew.SQL = sqltext


DoCmd.OpenQuery QryName

DoCmd.DeleteObject acQuery, QryName

'*************************<wbr ></wbr>**********<wbr ></wbr>**
' maybe routine needed here to check for concatenatedunwantedremova<wbr ></wbr>l wordcount and where no words add no trim level.

' all works fine till here where it fails on edit
sqltext = "SELECT ClientWordGroups.concatena<wbr ></wbr>ted, ClientWordGroups.Manufactu<wbr ></wbr>rerName, ClientWordGroups.Client, ClientWordGroups.Concatena<wbr ></wbr>tedUnwante<wbr ></wbr>dRemoval,"<wbr ></wbr> _
& " ClientWordGroups.MarqueAli<wbr ></wbr>as, ClientWordGroups.OriginalS<wbr ></wbr>tring, ClientWordGroups.Groups, ClientWordGroups.Concatena<wbr ></wbr>tedUnwante<wbr ></wbr>dRemovalCo<wbr ></wbr>py, QryWork.ClientName, QryWork.Marque," _
& " IIf(IsNull([concatenatedun<wbr ></wbr>wantedremo<wbr ></wbr>val])=True<wbr ></wbr>,True,isba<wbr ></wbr>semodel([c<wbr ></wbr>oncatenate<wbr ></wbr>dunwantedr<wbr ></wbr>emoval])) AS Expr1" _
& " FROM ClientWordGroups LEFT JOIN QryWork ON (ClientWordGroups.Client = QryWork.ClientName) AND (ClientWordGroups.MarqueAl<wbr ></wbr>ias = QryWork.Marque)" _
& " WHERE (((QryWork.ClientName) Is Not Null) AND ((QryWork.Marque) Is Not Null) AND ((IIf(IsNull([concatenated<wbr ></wbr>unwantedre<wbr ></wbr>moval])=Tr<wbr ></wbr>ue,True,is<wbr ></wbr>basemodel(<wbr ></wbr>[concatena<wbr ></wbr>tedunwante<wbr ></wbr>dremoval])<wbr ></wbr>))=True));<wbr ></wbr>"

Debug.Print sqltext

Set RstCUREmpty = Db.OpenRecordset(sqltext)
'
With RstCUREmpty
      .MoveLast
    countrecords = .RecordCount
 .MoveFirst
    'cycle through the recordset
    Do Until RstCUREmpty.EOF

'*************************<wbr ></wbr>****** error here

        .Edit
        
        .Fields("concatenatedunwan<wbr ></wbr>tedremoval<wbr ></wbr>").Value = "[no trim preclean new]"
        
        .Update
     .movenext   
    Loop

End With


RstCUREmpty.Close
Set RstCUREmpty = Nothing
Set Db = Nothing



DoCmd.SetWarnings True
End Function

Open in new window


i am in access vba

The recordset does have rows.

the actual sql is here:
SELECT ClientWordGroups.concatenated, ClientWordGroups.ManufacturerName, ClientWordGroups.Client, ClientWordGroups.ConcatenatedUnwantedRemoval, ClientWordGroups.MarqueAlias, ClientWordGroups.OriginalString, ClientWordGroups.Groups, ClientWordGroups.ConcatenatedUnwantedRemovalCopy, QryWork.ClientName, QryWork.Marque, IIf(IsNull([concatenatedunwantedremoval])=True,True,isbasemodel([concatenatedunwantedremoval])) AS Expr1
FROM ClientWordGroups LEFT JOIN QryWork ON (ClientWordGroups.MarqueAlias = QryWork.Marque) AND (ClientWordGroups.Client = QryWork.ClientName)
WHERE (((QryWork.ClientName) Is Not Null) AND ((QryWork.Marque) Is Not Null) AND ((IIf(IsNull([concatenatedunwantedremoval])=True,True,isbasemodel([concatenatedunwantedremoval])))=True));

Open in new window

0
Comment
Question by:PeterBaileyUk
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40300620
Try to run the strSQL manually. If it won't update, neither will your code.

/gustav
0
 

Author Comment

by:PeterBaileyUk
ID: 40300648
I've requested that this question be deleted for the following reason:

couldnt wait solved myself
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 40300649
i did that and solved it myself, i deleted the question as i didnt see your response, I have selected your answer now hopefully admin will deal with it.
regards
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question