David McAfee
davidmcafee at gmail.com
Thu May 24 19:58:46 CDT 2007
I tried these before, but they dont work when an empty string is passed:
' These two IsNull functions dont work when an empty string is passed,
so I used my own version above
'Public Function IsNull2(ByVal strInput As String, ByVal strReplace As
String) As String
' If (strInput.Equals(System.DBNull.Value)) Then
' Return strReplace
' End If
'End Function
'Public Function IsNull3(ByVal strInput As String, ByVal strReplace As
String) As String
' If (IsDBNull(strInput)) Then
' Return strReplace
' End If
'End Function
On 5/24/07, David Emerson <newsgrps at dalyn.co.nz> wrote:
>
> Thanks David,
>
> I originally had a similar syntax but was hoping that there was an
> shorter method.
>
> David
>
> At 25/05/2007, you wrote:
> >Here's a function I wrote (actually I wrote it for C#, but crossed it
> over
> >to vb.net)
> >
> > Public Function IsNull(ByVal strInput As String, ByVal strReplace As
> >String) As String
> > 'This works like SQL server's IsNull, not VB/VBA. In VB/VBA it
> is
> >known as Nz()
> > If (strInput Is Nothing) Then
> > Return strReplace
> > Else
> > If strInput = "" Then
> > Return strReplace
> > Else
> > Return strInput
> > End If
> > End If
> > End Function
> >
> >
> >On 5/24/07, David Emerson <newsgrps at dalyn.co.nz> wrote:
> > >
> > > Group,
> > >
> > > I am wanting to test the value of a field from a data source. If it
> > > is NULL or "" then do one thing, otherwise do another. Here is
> > my vb.netcode:
> > >
> > > If IsDBNull(Fields("MAddress2").Value) Or
> > > (Fields("MAddress2").Value = "") Then
> > > Me.txtMailAddress.DataField = "=MAddress1"
> > > Else
> > > Me.txtMailAddress.DataField = "=MAddress1" + Chr(34) +
> > > ", " + Chr(34) + " + MAddress2"
> > > End If
> > >
> > > The error message is "
> > >
> > > Operator '=' is not defined for type 'DBNull' and string "".
> > >
> > > What is the correct syntax for this?
> > >
> > >
> > > Regards
> > >
> > > David Emerson
> > > Dalyn Software Ltd
> > > Wellington, New Zealand
> > > _______________________________________________
> > > dba-VB mailing list
> > > dba-VB at databaseadvisors.com
> > > http://databaseadvisors.com/mailman/listinfo/dba-vb
> > > http://www.databaseadvisors.com
> > >
> > >
> >_______________________________________________
> >dba-VB mailing list
> >dba-VB at databaseadvisors.com
> >http://databaseadvisors.com/mailman/listinfo/dba-vb
> >http://www.databaseadvisors.com
>
> _______________________________________________
> dba-VB mailing list
> dba-VB at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-vb
> http://www.databaseadvisors.com
>
>