Improve company productivity with a Business Account.Sign Up

x
?
Solved

ADO: Field cannot be a zero-length string

Posted on 2001-07-11
9
Medium Priority
?
943 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 400 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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
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

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

607 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