PC Review


Reply
Thread Tools Rate Thread

Check function parameters for null Values

 
 
=?Utf-8?B?QnJ1Y2U=?=
Guest
Posts: n/a
 
      27th May 2005
I have written a function to dosomething and return the value to a text box
on my form. I want to pass 2 parameters from my form, i.e. cb_Product_1 and
cb_Product_2 but only if they are not null.

The following example in mytest1 worksbut requires hard coding the controls
in the code. I really need to specify parameters like in the second example
myTest2, but it gives me #error if I enter =
mytest2([cb_Product_1],[cb_SourcePlant_1]) as the formula in my textbox if
one or both of the parameters is null. When the statement is false (i.e. No
nulls), then it returns "Ok" which it should.

Why does mytest2 generate an error when the if statment is true?

Bruce....


Function mytest1()

a = [Forms]![frm_Price_Scenario]![cb_Product_1]
b = [Forms]![frm_Price_Scenario]![cb_SourcePlant_1]

If Nz(a) = "" Or Nz(b) = "" Then
mytest1 = ("Null")
Else
mytest1 = ("Ok")
End If

End Function




Function mytest2(a As String, b As Integer)

If Nz(a) = "" Or Nz(b) = "" Then
mytest2 = ("Null")
Else
mytest2 = ("Ok")
End If

End Function
 
Reply With Quote
 
 
 
 
=?Utf-8?B?RWluYXI=?=
Guest
Posts: n/a
 
      27th May 2005
Hi,

I think that you cannot pass NULL-values into the function where strings are
expected (normally generates Runtime Error 94). Try to change the string
datatype to Variant instead and then do the same test.

Einar

"Bruce" skrev:

> I have written a function to dosomething and return the value to a text box
> on my form. I want to pass 2 parameters from my form, i.e. cb_Product_1 and
> cb_Product_2 but only if they are not null.
>
> The following example in mytest1 worksbut requires hard coding the controls
> in the code. I really need to specify parameters like in the second example
> myTest2, but it gives me #error if I enter =
> mytest2([cb_Product_1],[cb_SourcePlant_1]) as the formula in my textbox if
> one or both of the parameters is null. When the statement is false (i.e. No
> nulls), then it returns "Ok" which it should.
>
> Why does mytest2 generate an error when the if statment is true?
>
> Bruce....
>
>
> Function mytest1()
>
> a = [Forms]![frm_Price_Scenario]![cb_Product_1]
> b = [Forms]![frm_Price_Scenario]![cb_SourcePlant_1]
>
> If Nz(a) = "" Or Nz(b) = "" Then
> mytest1 = ("Null")
> Else
> mytest1 = ("Ok")
> End If
>
> End Function
>
>
>
>
> Function mytest2(a As String, b As Integer)
>
> If Nz(a) = "" Or Nz(b) = "" Then
> mytest2 = ("Null")
> Else
> mytest2 = ("Ok")
> End If
>
> End Function

 
Reply With Quote
 
=?Utf-8?B?QnJ1Y2U=?=
Guest
Posts: n/a
 
      27th May 2005
Problem Solved. Thanks

"Einar" wrote:

> Hi,
>
> I think that you cannot pass NULL-values into the function where strings are
> expected (normally generates Runtime Error 94). Try to change the string
> datatype to Variant instead and then do the same test.
>
> Einar
>
> "Bruce" skrev:
>
> > I have written a function to dosomething and return the value to a text box
> > on my form. I want to pass 2 parameters from my form, i.e. cb_Product_1 and
> > cb_Product_2 but only if they are not null.
> >
> > The following example in mytest1 worksbut requires hard coding the controls
> > in the code. I really need to specify parameters like in the second example
> > myTest2, but it gives me #error if I enter =
> > mytest2([cb_Product_1],[cb_SourcePlant_1]) as the formula in my textbox if
> > one or both of the parameters is null. When the statement is false (i.e. No
> > nulls), then it returns "Ok" which it should.
> >
> > Why does mytest2 generate an error when the if statment is true?
> >
> > Bruce....
> >
> >
> > Function mytest1()
> >
> > a = [Forms]![frm_Price_Scenario]![cb_Product_1]
> > b = [Forms]![frm_Price_Scenario]![cb_SourcePlant_1]
> >
> > If Nz(a) = "" Or Nz(b) = "" Then
> > mytest1 = ("Null")
> > Else
> > mytest1 = ("Ok")
> > End If
> >
> > End Function
> >
> >
> >
> >
> > Function mytest2(a As String, b As Integer)
> >
> > If Nz(a) = "" Or Nz(b) = "" Then
> > mytest2 = ("Null")
> > Else
> > mytest2 = ("Ok")
> > End If
> >
> > End Function

 
Reply With Quote
 
=?Utf-8?B?S2xhdHV1?=
Guest
Posts: n/a
 
      27th May 2005
strReturn = mytest1(Nz([Forms]![frm_Price_Scenario]![cb_Product_1],""), _
& Nz([Forms]![frm_Price_Scenario]![cb_SourcePlant_1],""))

Function mytest1(a As string, b As String) As String

mytest1 = IIf(a="" or b="","Null", "Ok")

End Function

"Bruce" wrote:

> I have written a function to dosomething and return the value to a text box
> on my form. I want to pass 2 parameters from my form, i.e. cb_Product_1 and
> cb_Product_2 but only if they are not null.
>
> The following example in mytest1 worksbut requires hard coding the controls
> in the code. I really need to specify parameters like in the second example
> myTest2, but it gives me #error if I enter =
> mytest2([cb_Product_1],[cb_SourcePlant_1]) as the formula in my textbox if
> one or both of the parameters is null. When the statement is false (i.e. No
> nulls), then it returns "Ok" which it should.
>
> Why does mytest2 generate an error when the if statment is true?
>
> Bruce....
>
>
> Function mytest1()
>
> a = [Forms]![frm_Price_Scenario]![cb_Product_1]
> b = [Forms]![frm_Price_Scenario]![cb_SourcePlant_1]
>
> If Nz(a) = "" Or Nz(b) = "" Then
> mytest1 = ("Null")
> Else
> mytest1 = ("Ok")
> End If
>
> End Function
>
>
>
>
> Function mytest2(a As String, b As Integer)
>
> If Nz(a) = "" Or Nz(b) = "" Then
> mytest2 = ("Null")
> Else
> mytest2 = ("Ok")
> End If
>
> End Function

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Parameters And Null Values Stefan Hoffmann Microsoft Access Queries 0 3rd Dec 2009 03:55 PM
Invalid Use of Null on Function parameters Peter Hibbs Microsoft Access Form Coding 2 6th Jul 2009 04:45 PM
Parameter queries with multiple parameters and null values Amy Blankenship Microsoft Access Queries 5 26th Apr 2007 09:26 PM
Passing NULL values to SqlCommand.Parameters.AddWithValue Giammarco Microsoft ADO .NET 6 5th Jan 2007 04:59 PM
setting null values to parameters William \(Bill\) Vaughn Microsoft ADO .NET 2 30th Sep 2003 09:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:26 AM.