Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numeric textbox

Status
Not open for further replies.

Casiopea

Programmer
Jan 15, 2003
47
ES
I'm using a textbox to insert the age of a person.
Then I have assigned txt.Datafield=age, txt.DataSource=adolevel (adodc control) and the field "age" on the database table has numeric type. The problem exists when the field in the table has already a value and the user erase the value (txtbox in white) as the control lose the value it should be update on the table as null, however if fails and sends an error message (the typical one when the type is not correct) I guess that it understand that a blank is not numeric or null.
The other controls don't give me this problem (text or date). I know that I could take this text box control off the field and do it manually; before updating controlling if the textbox is white and assigning rs.Fields("age")=null.
But I would like to know if I can do it automatically.

Thank you.
 

If txt & "" = "" Then 'Check for empty & Null
rs.Fields("age")=NULL
ElseIf IsNumeric(txt & "e0") Then 'No scientific values
rs.Fields("age")=txt
Else
msgbox "No text pls!"
End If
 

Jerry, that is just what they didn't want to have to do, as the text box is bound to a recordset.

Casiopea, simply use the MS Data Formating Object for this. That is what it is there for, among other things. First look it up in VB help, try to get it working, and then report back what is not working or understood.
 
[smile]

But it has nothing to do with the ADODC, but with the fact that the text boxes are bound - whether to a DC or to a recordset object, it doesn't matter, and an empty string is getting passed to the update.

Using the recordset's WithEvents and if desired, the Data Formating Object, anything and everything can be intercepted with a bound control and prevent the DB table from automatically updating (you could even just disconnect the recordset). These features make using a bound control (text boxes, grid, etc) a very neat instrument with basically no undesired side effects, as was the case in the past.
I just wouldn't use the [blaa] Data Control at all, but bind the controls (text boxes, grid, etc) to the recordset object directly.
 
I use the Data Control all the time in classes, to create quick demos that display data.

But then I tell everyone not to use it. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top