Results 1 to 5 of 5

Thread: date input

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    70

    date input

    I have th efollwowing code to enter a record.
    when I leave the date field blank and press udpade
    I get an error meassage.

    is there a way of making my program accept blank entries for the date field? I get the same problem with currency

    Private Sub Command1_Click()

    Data1.Recordset.AddNew
    Data1.Recordset("Name") = Text1
    Data1.Recordset("Start_Date") = Text2.Text
    Data1.Recordset("End_Date") = Text3.Text
    Data1.Recordset("Currency") = Text4.Text
    Data1.Recordset.Update

    End Sub

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    A "blank entry" in a text box is considered an empty string. You cannot set a numeric or date to an empty string. You will need to add some validation checks when setting your recordset values.

    If your database does not allow nulls then you must supply a value.

    If Len(Trim$(Text2.Text)) > 0 Then
    Data1.Recordset("Start_Date") = Text2.Text
    Else
    Data1.Recordset("Start_Date") = Null
    End If


    Data1.Recordset("Currency") = Val(Text4.Text) 'this will equate to 0 if the textbox is empty.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    70
    Fantastic, Thanks a lot!

    just one more question:

    I have this error handling statement:

    on error goto fix:

    fix: data1.Recordset.CancelUpdate

    on the same statement i.e. fix I want to add this:

    MsgBox "If a field is not filled in please enter N/A. This Record will not be saved", vbExclamation

    I want this to come up along with CancelUpdate, but when I put it on the same line as data1.Recordset.CancelUpdate, I get a message saying "Expected end of statement"

    Is there a way of doing what I want to do?

  4. #4
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Type in on a separate line
    Code:
    fix: 
    data1.Recordset.CancelUpdate 
    MsgBox "If a field is not filled in please enter N/A. This Record will not be saved", vbExclamation

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    70
    it doen't work, the msgbox still comes up if there is no blank entry!

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