473,378 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Getting error on VBA routine

114 100+
Hi to all. Trying to get a onclick VBA routine to run, but I'm getting an error message when I click on the button that is used to run the VBA code to change/update a memo field in a table. This routine is only called one time after the table is reloaded monthly. There is data in this memo field that needs to be converted, exam "<crlflf>" should be changed to "Chr(13) Chr(10) Chr(10)".

The error message I receive is "Update or CancelUpdate without AddNew or Edit". Hope someone can help me and thanks in advance.

Here is the code for the onclick:
================================================== ===
Expand|Select|Wrap|Line Numbers
  1. Private Sub FixMemoField_Click()
  2. On Error GoTo Err_FixMemoField_Click
  3.  
  4. Dim rs As DAO.Recordset
  5. Set rs = CurrentDb.OpenRecordset("Translated_memo")
  6.  
  7. While Not rs.EOF
  8. rs.Update
  9. rs!memofieldname = Replace(rs!trans_memo, "<crlf>", Chr(13) & Chr(10))
  10. rs!memofieldname = Replace(rs!trans_memo, "<crlflf>", Chr(13) & Chr(10) & Chr(10))
  11. rs.Update
  12. rs.MoveNext
  13. Wend
  14.  
  15. Exit_FixMemoField_Click:
  16.     Exit Sub
  17.  
  18. Err_FixMemoField_Click:
  19.     MsgBox Err.Description
  20.     Resume Exit_FixMemoField_Click
  21.  
  22. End Sub
Mar 3 '07 #1
8 2384
ljungers
114 100+
I took another look at the code and saw that "rs.Update" was used 2 times n the code. I deleted the 1st occurance of it and tried to run it.

I now get the following message "Item not found in this collection". Anyone have an idea of what is happening.
Mar 3 '07 #2
NeoPa
32,556 Expert Mod 16PB
Go back to the original version but replace the first rs.Update with an rs.Edit.
So, you should have :
Expand|Select|Wrap|Line Numbers
  1.   ...
  2.   rs.Edit
  3.   'Various lines of updating
  4.   rs.Update
  5.   rs.MoveNext
  6.   ...
Mar 4 '07 #3
ADezii
8,834 Expert 8TB
Hi to all. Trying to get a onclick VBA routine to run, but I'm getting an error message when I click on the button that is used to run the VBA code to change/update a memo field in a table. This routine is only called one time after the table is reloaded monthly. There is data in this memo field that needs to be converted, exam "<crlflf>" should be changed to "Chr(13) Chr(10) Chr(10)".

The error message I receive is "Update or CancelUpdate without AddNew or Edit". Hope someone can help me and thanks in advance.

Here is the code for the onclick:
================================================== ===
Expand|Select|Wrap|Line Numbers
  1. Private Sub FixMemoField_Click()
  2. On Error GoTo Err_FixMemoField_Click
  3.  
  4. Dim rs As DAO.Recordset
  5. Set rs = CurrentDb.OpenRecordset("Translated_memo")
  6.  
  7. While Not rs.EOF
  8. rs.Update
  9. rs!memofieldname = Replace(rs!trans_memo, "<crlf>", Chr(13) & Chr(10))
  10. rs!memofieldname = Replace(rs!trans_memo, "<crlflf>", Chr(13) & Chr(10) & Chr(10))
  11. rs.Update
  12. rs.MoveNext
  13. Wend
  14.  
  15. Exit_FixMemoField_Click:
  16.     Exit Sub
  17.  
  18. Err_FixMemoField_Click:
  19.     MsgBox Err.Description
  20.     Resume Exit_FixMemoField_Click
  21.  
  22. End Sub
Expand|Select|Wrap|Line Numbers
  1. Dim rs As DAO.Recordset
  2. Set rs = CurrentDb.OpenRecordset("Translated_memo")
  3.  
  4. Do While Not rs.EOF
  5.    If Not IsNull(rs![memofieldname]) Then
  6.        rs.Edit
  7.           rs!memofieldname = Replace(rs!memofieldname, "<crlf>", Chr(13) & Chr(10))
  8.           rs!memofieldname = Replace(rs!memofieldname, "<crlflf>", Chr(13) & Chr(10) & Chr(10))
  9.        rs.Update
  10.    End If
  11.    rs.MoveNext
  12. Loop
  13.  
  14. rs.Close
Mar 4 '07 #4
ljungers
114 100+
I corrected the script as shown in last post. I added a command button to my form so that when the ascii text file that is imported into Access each month, this routine can be run. When I click on it the disk drive light flickers and it looks as nothing is happening. I never get the msg box showing that it completed.

=========================================
Private Sub FixMemoField_Click()
On Error GoTo Err_FixMemoField_Click

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("Translated_memo")

Do While Not rs.EOF
If Not IsNull(rs![trans_memo]) Then
rs.Edit
rs!trans_memo = Replace(rs!trans_memo, "<crlf>", Chr(13) & Chr(10))
rs!trans_memo = Replace(rs!trans_memo, "<crlflf>", Chr(13) & Chr(10) & Chr(10))
rs.Update
End If
rs.MoveNext
Wend

MsgBox ("The updates have completed!")

Exit_FixMemoField_Click:
Exit Sub

Err_FixMemoField_Click:
MsgBox Err.Description
Resume Exit_FixMemoField_Click

End Sub
Mar 9 '07 #5
ADezii
8,834 Expert 8TB
I corrected the script as shown in last post. I added a command button to my form so that when the ascii text file that is imported into Access each month, this routine can be run. When I click on it the disk drive light flickers and it looks as nothing is happening. I never get the msg box showing that it completed.

=========================================
Private Sub FixMemoField_Click()
On Error GoTo Err_FixMemoField_Click

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("Translated_memo")

Do While Not rs.EOF
If Not IsNull(rs![trans_memo]) Then
rs.Edit
rs!trans_memo = Replace(rs!trans_memo, "<crlf>", Chr(13) & Chr(10))
rs!trans_memo = Replace(rs!trans_memo, "<crlflf>", Chr(13) & Chr(10) & Chr(10))
rs.Update
End If
rs.MoveNext
Wend

MsgBox ("The updates have completed!")

Exit_FixMemoField_Click:
Exit Sub

Err_FixMemoField_Click:
MsgBox Err.Description
Resume Exit_FixMemoField_Click

End Sub
Replace Wend with Loop:
Expand|Select|Wrap|Line Numbers
  1. Do While Not rs.EOF
  2.     If Not IsNull(rs![trans_memo]) Then
  3.         rs.Edit
  4.             rs!trans_memo = Replace(rs!trans_memo, "<crlf>", Chr(13) & Chr(10))
  5.             rs!trans_memo = Replace(rs!trans_memo, "<crlflf>", Chr(13) & Chr(10) & Chr(10))
  6.         rs.Update
  7.     End If
  8.     rs.MoveNext
  9. Wend <== DO NOT USE!
  10. Loop
Mar 9 '07 #6
NeoPa
32,556 Expert Mod 16PB
If you want to use Wend then it comes in the format below.
Expand|Select|Wrap|Line Numbers
  1. While {condition}
  2.   ...
  3. Wend
Otherwise, ADezii's Do...Loop is a perfectly adequate alternative.
The Do...Loop format is actually more flexible as you can use 'While' OR 'Until', and you can either put them with the 'Do' or with the 'Loop'.
Mar 9 '07 #7
ljungers
114 100+
I forgot to thank you ADezii and NeoPa for your help. That VBA routine works now and performs the way it should.

Thanks to both of you.
Mar 11 '07 #8
ADezii
8,834 Expert 8TB
I forgot to thank you ADezii and NeoPa for your help. That VBA routine works now and performs the way it should.

Thanks to both of you.
Glad to help ya.
Mar 11 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: IMS.Rushikesh | last post by:
Hi Friends, My work is stuck up because of this unresolvable and unbelievable Error. I'm trying to Serialize my Class object using XmlSerialization. And at below line, I m getting "error File...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
0
by: Roger Twomey | last post by:
I am writing a Windows service which is run (and tested) at a remote location so I cannot debug issues at the actual deployment site. I know that the application is having some sort of trouble as...
5
by: Archana | last post by:
Hi all, I am having application where i am downloading xml content using webrequest. my code is as below HttpWebRequest lWebRequest = (HttpWebRequest) WebRequest.Create(URL); HttpWebResponse...
1
by: jonny | last post by:
Went from using Visual Web Develop express to Visual Studio 2005 and getting error when trying to open project. Error message: "One or more projects in the solution could not be loaded for the...
21
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support...
2
by: sony.m.2007 | last post by:
Hi, When i try to set a value for a session variable I'm getting a object refence not set error I tried two methods as below HttpContext.Current.Session.Add("AppStartTime", DateTime.Now);...
4
by: sumit kale | last post by:
Hi, Can somebody help me resolve my problem ? I am getting error when calculating total using unbound textfiled in subform. I have a main form called purchase_register_master and a subform...
12
by: tvnaidu | last post by:
Trying to mount windows folder on Linux machine, getting this error. I have a folder called "CheckIn" on windows, I made that folder as Network sharing. ON lInux, I tried to access that folder by...
2
by: bandy | last post by:
Hi there sorry If I posted this thread under wrong head. When I am trying to run my site I am getting error as Internal Server Error, but when I refresh page , i get result properly. I don't...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.