Solved

ADO: Field cannot be a zero-length string

Posted on 2001-07-11
9
869 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
 
LVL 1

Author Comment

by:nguyenn
ID: 6274500
Hi John

But it doesnt solve problem when I update [DeviceName] to a null value
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now