Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ADO: Field cannot be a zero-length string

Posted on 2001-07-11
9
883 Views
Last Modified: 2007-11-27
I'm using ADO to create a recordset (adoTemp) from my existed database (called myTable). Anytime adding a null value to one of my string Field (DeviceName), I got an runtime error:

-214721887 : Field 'myTable.DeviceName' cannot be a zero length.


Here is my code:
Command1_Click()
   Dim adoTemp as ADODB.Recordset
   Dim strSQL as String
   Dim intDeviceID as Integer
   Dim strDeviceName as String

   strSQL = "Select * From myTable"
   set adoTemp = new ADODB.Recordset
   adoTemp.Open strSQL, myConnection, adOpenKeyset, adLockOptimistic, adCmdText

   .........
   intDeviceID = 1
   strDeviceName = ""

   adoTemp.AddNew
   adoTemp("DeviceID") =intDeviceID
   adoTemp("DeviceName") = strDeviceName
   adoTemp.Update
End Sub


Could anyone helps me solve this problem? [DeviceName] sometimes has a null value


Thanks in advance
nguyenn
0
Comment
Question by:nguyenn
  • 4
  • 3
  • 2
9 Comments
 
LVL 7

Expert Comment

by:John844
ID: 6274479
null and zero length string are two different things
database can allow nulls without allowing zero length strings for this field.
0
 
LVL 7

Expert Comment

by:John844
ID: 6274484
try changing
  adoTemp("DeviceName") = strDeviceName

to
  if strDeviceName = "" then
    'do nothing so null will go into field
  else
    adoTemp("DeviceName") = strDeviceName
  end if
0
 
LVL 7

Accepted Solution

by:
John844 earned 100 total points
ID: 6274494
if you need to update the field at some point, use similar logic to update field to vbNull if the string is ""
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:nguyenn
ID: 6274500
Hi John

But it doesnt solve problem when I update [DeviceName] to a null value
0
 
LVL 7

Expert Comment

by:John844
ID: 6274511
anothir way to allow zero length string is to go into design mode of your table.  click on the field in question.  at the bottom left corner of your window there will be a item "Allow Zero Length" = No.  Change this to Yes.  This will allow your existing code to be used, but it will not put a null into the field, it will be a zero length string like "".

Hope some of this helps you solve your current problem.
John
0
 
LVL 1

Author Comment

by:nguyenn
ID: 6274512
Thanks a bunch John, it helps me out

Have a nice day :)
0
 
LVL 20

Expert Comment

by:hes
ID: 6274518
How is DeviceName defined in the database table. Is it defined to allow zero length.
0
 
LVL 1

Author Comment

by:nguyenn
ID: 6274623
Hi Hes,

You're right, I didnt set allow zero lenght to Yes in the database.

Thanks for mention it
nguyenn
0
 
LVL 20

Expert Comment

by:hes
ID: 6274908
Glad you got it solved,
John and I were typing that at the same time :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

809 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