473,394 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Null value won't pass into function

Hi All,

I have started tearing my hair out over this problem!

I am pulling some data from a table and passing it as variables into a function in Access. One of the variables I'm passing through can be Null, so to avoid trying to pass a Null value to a function as a string (which I gather Access wouldn't like) I created an IIF function inside the parameters so if the value was null, it passed the string "NULLDEPOT" into the function, and I dealt with it inside the function.

No matter HOW I try (stacked queries, new variables, taking the IIF out of the function parameters and creating it earlier)...I always get an "#Error" value returned. Even when I set a breakpoint at the top of the function, Access won't trip it if that value was ever Null, however every other value works fine?!

I'll include my code below:

Query code:
Expand|Select|Wrap|Line Numbers
  1. VendorCode: Supplier("13",[AGCECOM],[PMC],[Supplier Number],IIf([DepotID] Is Null,"NULLDEPOT",[DepotID]))
VB Function Code:
Expand|Select|Wrap|Line Numbers
  1. Public Function Supplier(OrigDep As String, AgCE As String, PMC As String, VendNum As String, MainDepot As String) As String
  2.     Dim TempSupplier As String
  3.  
  4. ...snip...
  5.  
  6.     ElseIf OrigDep = "13" Then
  7.         If MainDepot = "NULLDEPOT" Then
  8.             TempSupplier = "N"
  9.         ElseIf MainDepot = "13" Then
  10.             TempSupplier = VendNum
  11.         Else
  12.             TempSupplier = "1400000"
  13.         End If
  14.  
  15. ...snip...
  16.  
  17.     Else
  18.         TempSupplier = "N"
  19.     End If
  20.  
  21.     ' AgCE and PMC Logic Final Override
  22.     If AgCE = "CE" Or PMC = "V" Then
  23.         TempSupplier = "ZZZ"
  24.     End If
  25.  
  26.     ' Return string
  27.     Supplier = TempSupplier
  28.  
  29. End Function
  30.  
Please HELP!!!
May 18 '07 #1
4 10272
Rabbit
12,516 Expert Mod 8TB
Hi All,

I have started tearing my hair out over this problem!

I am pulling some data from a table and passing it as variables into a function in Access. One of the variables I'm passing through can be Null, so to avoid trying to pass a Null value to a function as a string (which I gather Access wouldn't like) I created an IIF function inside the parameters so if the value was null, it passed the string "NULLDEPOT" into the function, and I dealt with it inside the function.

No matter HOW I try (stacked queries, new variables, taking the IIF out of the function parameters and creating it earlier)...I always get an "#Error" value returned. Even when I set a breakpoint at the top of the function, Access won't trip it if that value was ever Null, however every other value works fine?!

I'll include my code below:

Query code:
Expand|Select|Wrap|Line Numbers
  1. VendorCode: Supplier("13",[AGCECOM],[PMC],[Supplier Number],IIf([DepotID] Is Null,"NULLDEPOT",[DepotID]))
VB Function Code:
Expand|Select|Wrap|Line Numbers
  1. Public Function Supplier(OrigDep As String, AgCE As String, PMC As String, VendNum As String, MainDepot As String) As String
  2.     Dim TempSupplier As String
  3.  
  4. ...snip...
  5.  
  6.     ElseIf OrigDep = "13" Then
  7.         If MainDepot = "NULLDEPOT" Then
  8.             TempSupplier = "N"
  9.         ElseIf MainDepot = "13" Then
  10.             TempSupplier = VendNum
  11.         Else
  12.             TempSupplier = "1400000"
  13.         End If
  14.  
  15. ...snip...
  16.  
  17.     Else
  18.         TempSupplier = "N"
  19.     End If
  20.  
  21.     ' AgCE and PMC Logic Final Override
  22.     If AgCE = "CE" Or PMC = "V" Then
  23.         TempSupplier = "ZZZ"
  24.     End If
  25.  
  26.     ' Return string
  27.     Supplier = TempSupplier
  28.  
  29. End Function
  30.  
Please HELP!!!
Try using Nz() instead of the iif function.
May 18 '07 #2
Try using Nz() instead of the iif function.
Already tried that Rabbit and I get the same error.

Any other suggestions?
May 18 '07 #3
Already tried that Rabbit and I get the same error.

Any other suggestions?

Nevermind, found my own answer. All inbound function variables should be declared as Variants and then deal with the NZ() function inside my custom function.
May 18 '07 #4
Rabbit
12,516 Expert Mod 8TB
Excellent. Always better when the PO finds their own answer.
May 18 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Oleg | last post by:
I am trying to send one of the parameters of stored procedure having a null value. The parameter is of type blob. I declare it in code like 'new OleDbParameter ("p_sigPicture",...
3
by: Robb Gilmore | last post by:
Hello, We have a C#.NET app which is calling a Java webservice. We use the wsdl file exportted from the java webservice to create our web-reference in Visual Studio. We are able to create the...
3
by: Michael Tissington | last post by:
I have a DLL written in C++ and I'm calling it from C# One of the parameters for a function in the DLL is a DATE value or NULL. How do I pass NULL to my DLL from C#? -- Michael Tissington...
0
by: Dana | last post by:
I am using the XMLTextWriter to build an XML string and pass it to the XMLDocument. When I get the data from SQL Server, some of the values passed to the XML are NULL in the database. When I try...
2
by: PK | last post by:
Hi, I have an application that opens a Crystal report document and passes in a value to a parameter in the report (pointing to an Oracle DB). However, if I want to pass a "null" value to retrieve...
1
by: David Shorthouse | last post by:
Hey folks, I am attempting to pass null as the input value from a series of textboxes if the user does not input a value prior to submit. To try and do this, I am using a vbscript function on...
3
by: fniles | last post by:
I am accessing MS Access db with tblA whose column UNABLE can have NULL value. When I access UNABLE whose value is null, I got an error " Run-time exception thrown : System.InvalidCastException -...
7
by: kumar.senthil | last post by:
Hi, I'm using XmlSerializer to create an object from the XML string. I would like to know whether I can get a null value for an empty XML element. Actually the XmlSerializer assigns "" (empty...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.