|
-
Mar 20th, 2003, 10:40 AM
#1
Thread Starter
Lively Member
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
-
Mar 20th, 2003, 11:00 AM
#2
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.
-
Mar 20th, 2003, 04:19 PM
#3
Thread Starter
Lively Member
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?
-
Mar 20th, 2003, 06:08 PM
#4
Frenzied Member
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
-
Mar 21st, 2003, 11:45 AM
#5
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|