|
-
Dec 11th, 2001, 01:07 PM
#1
Empty Textbox
I want to ask one question, I hope someone can help me.
When I add a new record to database, I write this code:
rs.AddNew
rs![Name] = txtName
rs![Closedate] = txtClosedate.
rs![Cost] = txtCost
rs.update
rs.Close
db.Close
In Access database, [Name] is a text, [Closedate] is a date/time, [Cost] is a number. And all the Required = No in their field properties.
The problem is if the user only input the name, but the txtClosedate and txtCost is empty, because it's open, it isn't necessary to close and without cost right now. When you click the Save button, it causes a "Data Type conversion error".
I know Name I can check Allow Zero Length = yes, then whatever you enter nothing, it does't has error, but I don't know how to handle the date/time and number.
Welcome email to me or post on board
Thanks a lot!
Joanny
-
Dec 11th, 2001, 01:11 PM
#2
Hyperactive Member
how is the data input??
input box
or
textbox on a form?
-
Dec 11th, 2001, 01:14 PM
#3
Re: Empty Textbox
Originally posted by Joanny
I want to ask one question, I hope someone can help me.
When I add a new record to database, I write this code:
They will get the data from TEXT box
rs.AddNew
rs![Name] = txtName
rs![Closedate] = txtClosedate.
rs![Cost] = txtCost
rs.update
rs.Close
db.Close
In Access database, [Name] is a text, [Closedate] is a date/time, [Cost] is a number. And all the Required = No in their field properties.
The problem is if the user only input the name, but the txtClosedate and txtCost is empty, because it's open, it isn't necessary to close and without cost right now. When you click the Save button, it causes a "Data Type conversion error".
I know Name I can check Allow Zero Length = yes, then whatever you enter nothing, it does't has error, but I don't know how to handle the date/time and number.
Welcome email to me or post on board
Thanks a lot!
Joanny
-
Dec 11th, 2001, 01:15 PM
#4
They are getting the data from TEXT boxes
Joanny
-
Dec 11th, 2001, 01:16 PM
#5
How about something like
VB Code:
Dim DateCheck As Date
If IsNull(txtCost.Text) Then
rs![Cost]=0
Else
rs![Cost]=Val(txtCost.Text)
End If
DateCheck = IsDate(txtCloseDate.Text)
If DateCheck = True Then
rs![CloseDate]=CDate(txtCloseDate.Text)
End If
-
Dec 11th, 2001, 01:21 PM
#6
how about if the txtClosedate.text = "", how can I do?
Joanny
-
Dec 11th, 2001, 01:23 PM
#7
If is equals "" then DateCheck will equal False, and nothing will get written back to the table.
-
Dec 11th, 2001, 01:25 PM
#8
Hyperactive Member
Can you just set your access table for default values
and Required = to NO
that way if
IF txtClosedate.text <> "" then
rs![Closedate] = txtClosedate
ELSE
'Do nothing
rs.update
-
Dec 11th, 2001, 02:58 PM
#9
My code is predicated on the fact that CloseDate is not a required field.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|