Results 1 to 9 of 9

Thread: Empty Textbox

  1. #1
    Joanny
    Guest

    Question 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

  2. #2
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489
    how is the data input??
    input box
    or
    textbox on a form?

  3. #3
    Joanny
    Guest

    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

  4. #4
    Joanny
    Guest
    They are getting the data from TEXT boxes

    Joanny

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    How about something like
    VB Code:
    1. Dim DateCheck As Date
    2. If IsNull(txtCost.Text) Then
    3.      rs![Cost]=0
    4. Else
    5.     rs![Cost]=Val(txtCost.Text)
    6. End If
    7.  
    8. DateCheck = IsDate(txtCloseDate.Text)
    9. If DateCheck = True Then
    10.    rs![CloseDate]=CDate(txtCloseDate.Text)
    11. End If

  6. #6
    Joanny
    Guest
    how about if the txtClosedate.text = "", how can I do?

    Joanny

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    If is equals "" then DateCheck will equal False, and nothing will get written back to the table.

  8. #8
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489
    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

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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
  •  



Click Here to Expand Forum to Full Width