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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move null dates from oracle database to vb6 form 1

Status
Not open for further replies.

Lhuffst

Programmer
Jun 23, 2003
503
US
A form that has worked for years is not getting a datatype mismatch (runtime error 13) and I don't understand why or how to fix it.
Basically, I'm retrieving a recordset from an oracle database and placing the values in textboxes. For date fields, I now get the error if the database field is null. Can someone tell me what needs to be changed to allow text boxes to accept null values?
Code:
 txtLine1.Text = 
IIf(IsNull(rs("WatermeterDate")), Null, Format(rs("WATERMETERDATE"), "mm/DD/yy"))
 txtline2.Text = 
IIf(IsNull(rs("WaterLeakageDate")), "", Format(rs("WATERLeakageDATE"), "mm/DD/yy"))
The 2nd date is how it's always been and I just tried to substitute the Null value but get same error.
Thanks
lhuffst
 
It's been a while since I've worked with VB6, but the following is a .Net version of the NotNull function I used to use to handle that exact problem. Just convert this back to VB6 (don't have it installed anymore or I'd post it):
Code:
'Example of usage:  txtInvNum.Text = NotNull(InqDt.Rows(0).Item("InvNum"), "")

	Public Function NotNull(ByVal dbArg As Object, Optional ByVal DefaultVal As String = "") As String
		'This is used to clean up any NULLS coming OUT of the database.
		'   You can set a default value if the DB Argument is NULL.
		'   Default return value is "".
		NotNull = ""
		Try
			If dbArg Is Nothing Then
				NotNull = DefaultVal
			Else
				If String.IsNullOrEmpty(dbArg.ToString) = True Then
					NotNull = DefaultVal
				Else
					NotNull = dbArg.ToString
				End If
			End If
		Catch Ex As Exception
			NotNull = DefaultVal
		End Try
	End Function

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
finally determined that it wasn't my code to load the combo boxes but invalid dates (1801, 0010) being stored as the year. When I did the debug, these showed up as nulls. I forced the dates to be displayed as 4 digit years to avoid this problem. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top