473,397 Members | 2,077 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,397 software developers and data experts.

Problem with ADO AddNew

38
The code below works in that I can insert records into the recordset.

Sub SaveRecord()
With rsRecord
.AddNew
![projid] = Me!Proj_Id
![ProjName] = Me!Proj_Name
![CatId] = Me!Cat_Id
.Update
End With
End Sub

As long as the values are valid against the field definition of the table. For example projid is string with len of 10. The problem starts when I enter more than 10 charcater. At first, I get an error message indicating that the string is too long for DB field. after which, I make the correction but when I get to executing the AddNew again, the value for projid does not get set to that of the me!proj_id from the form. It as though after an error it ignores resetting the values and it throws an exception.

Is there something I'm missing? Do I have to clear any error conditions after a failed ADO event?

I greatly appreciate your help.
Salzan
Feb 14 '08 #1
3 1633
missinglinq
3,532 Expert 2GB
Don't have a clue, Salzan, perhaps someone else here does, but I suspect is comes under the category of the "Joys of Unbound Forms!" Which is why most people avoid them like the plague! Since you lose all those nice on-going monitoring services that are inherent in Access when you go the unbound route, I would think you need to be extra diligent in setting up your own procedures to insure that the data you're about to insert is valid. The code below, for instance, will limit the number of characters entered into an unbound textbox to 10:
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourTextBox_Change()
  2.  If Len(Me.YourTextBox.Text) = 11 Then
  3.   MsgBox "This Field Can Only Hold 10 Characters"
  4.   Me.YourTextBox.Text = Left(Me.YourTextBox.Text, 10)
  5.  End If
  6. End Sub
  7.  
You'd also need to be sure that numeric fields hold numeric data, date fields hold dates, etc.

Linq ;0)>
Feb 14 '08 #2
salzan
38
Thank you but I didn't give up to easily. Trail and error led me to:

.CancelUpdate method

...which once placed in the exception handling section resets the recordset.
Feb 14 '08 #3
missinglinq
3,532 Expert 2GB
Glad you got it solved to your satisfaction! But if someone other than yourself is going to be using this app, you should still think about validating your data before trying to write it to the table. While you might understand the esoteric error messages Access puts out when something like this occurs, the average user may not.

Good luck!

Linq ;0)>
Feb 15 '08 #4

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

Similar topics

2
by: Tim Marshall | last post by:
ODBC situation, Access 97, here is the code and I've marked where Access coughs up. The Access error message is 3027, can't update, database is read only. The Oracle table in question has a...
0
by: Jongmin | last post by:
I met a problem when implementing IBindingList interface. I made CustomerList class, copied from MSDN, to implement CollectionBase and IBindingList. My problem took place after setting...
5
by: Mika M | last post by:
Hello! I have Windows Forms application form containing TextBoxes, six ComboBoxes, and DataGrid for details. I have created DataSet with needed tables, and created relations between tables, and...
2
by: guy | last post by:
if i use Generics.AddNew how do I pass an object to the items constructor? I have a set of class all inheriting from a base class, all requiring one parameter on their constructor - the data...
2
by: pillmill | last post by:
I replaced AddNew statments with INSERT INTO, but am unable to write to the same tables. Foreign keys violations are the main errors. Why are these occuring ? Before: set rs3=...
8
by: MLH | last post by:
Here's a snippet from A97 HELP on AddNew... The record that was current before you used AddNew remains current. If you want to make the new record current, you can set the Bookmark property to...
2
by: andraandjeff | last post by:
Hi everyone, I've got an ADO AddNew update query in VBA. Some of the fields may be empty and I want to know if there is an easier way than writing If statements around each field to test for...
1
damonreid
by: damonreid | last post by:
Access 2003 Microsoft Windows XP Pro Hey, I am currently pulling my hair out here. I have a Form for adding new projects to a database, the only problem is that when I close the form it doesn't...
0
nev
by: nev | last post by:
Have any of you encountered this? And how did you correct it? bs.addnew() automatically moves the position to the new record. But mine doesn't. I have 3 bindingsources in my program, all...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.