[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 142
  • Last Modified:

Using Data Controls and Nulls

Hi.  I have created a simple application.   It has a dBase database with only 2 fields.  Name, and age.  Name
is a text field, and age is a numeric field.    On my VB app, I have a data control linked to the database, and two text boxes linked to the fields.  I have another button labeled Update.   When I run the program, I use my data
control to move through the records.  But, if I stop on a record, and delete the age that was there, and hit my update button, it  gives me a data conversion error, because I'm not storing a numeric value in the age field.  How can I
make my program allow storing of empty strings in a numeric field???

0
ssteeves
Asked:
ssteeves
1 Solution
 
MikeP090797Commented:
There is no way you can store string in such field, but you can store 0, and when your record loads, replace it with "" in the textbox
0
 
watyCommented:
You could use a function like the following. It works in all the
cases, and doesn't break for NULL values.

Function ReadRecordSet(record As Recordset, szChamps As String)
   ' *** Check for NULL value

   If IsNull(record(szChamps)) Then
      Select Case VarType(record(szChamps))
         Case vbLong: ReadRecordSet = 0
         Case vbString: ReadRecordSet = ""
         Case vbDate: ReadRecordSet = "01/01/1980"
      End Select
   Else
      ReadRecordSet = record(szChamps)
   End If

End Function

0
 
ssteevesAuthor Commented:
That's pretty much what I did.  Thanks for the help guys.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now