474,044 Members | 2,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass null-value to function (How to..)

Hi to all,

just ran into a problem:
I wrote a function which works with several values collected on a
form. I thought it would be no problem, if the fields were empty,
because I made the function taking care of null-values.

Then I realized that I get an error when I try to pass the values like
that:

DatNext = A_Task_Next_Fct (Me![Task_ID],
Me![Task_Cycle],Me![Date_First, Me![Date_Last])

whenever one of the fields is empty.

What would be the correct way to handle this?

Thanks in advance.

Uwe
Nov 12 '05 #1
7 14775
Good Question. I will await a response from the experts, too. I think that
functions cannot have null parameters unless they are designated as
optional. I haven't experimented with optional parameters yet. What I do
instead is pass zero-length strings instead of nulls to the function, ie:
MyFunc(NZ(MyPar ameter,"")). I hope someone with more experience responds...
Fred Zuckerman
San Diego, CA, USA
"Uwe Range" <ur****@gmx.d e> wrote in message
news:64******** *************** ***@posting.goo gle.com...
Hi to all,

just ran into a problem:
I wrote a function which works with several values collected on a
form. I thought it would be no problem, if the fields were empty,
because I made the function taking care of null-values.

Then I realized that I get an error when I try to pass the values like
that:

DatNext = A_Task_Next_Fct (Me![Task_ID],
Me![Task_Cycle],Me![Date_First, Me![Date_Last])

whenever one of the fields is empty.

What would be the correct way to handle this?

Thanks in advance.

Uwe

Nov 12 '05 #2
If the arguments are defined as Variants then you can pass Null values.

e.g.

Function A_Task_Next_Fct ( _
varTask_ID as Variant, _
varTask_Cycle as Variant, _
varDate_First as Variant, _
varDate_Last as Variant)
You can also declare it as

Function A_Task_Next_Fct ( _
varTask_ID, _
varTask_Cycle, _
varDate_First, _
varDate_Last)

As Variant is the default data type, but by declaring it fully you make it
clear that this is the datatype you want.

--
Terry Kreft
MVP Microsoft Access

"Uwe Range" <ur****@gmx.d e> wrote in message
news:64******** *************** ***@posting.goo gle.com...
Hi to all,

just ran into a problem:
I wrote a function which works with several values collected on a
form. I thought it would be no problem, if the fields were empty,
because I made the function taking care of null-values.

Then I realized that I get an error when I try to pass the values like
that:

DatNext = A_Task_Next_Fct (Me![Task_ID],
Me![Task_Cycle],Me![Date_First, Me![Date_Last])

whenever one of the fields is empty.

What would be the correct way to handle this?

Thanks in advance.

Uwe

Nov 12 '05 #3
Uwe

You say that the function accepts nulls as parameters are you sure?
you haven't written it like A_Task_Next_Fct (myTask as long etc. etc)
If you are sure that it accepts nulls then is this what you are you
passing?
Does me![TaskID] default to 0 for instance?
It would help to know what the function does, what the error message
is & what line of code causes the error.

Neil
ur****@gmx.de (Uwe Range) wrote in message news:<64******* *************** ****@posting.go ogle.com>...
Hi to all,

just ran into a problem:
I wrote a function which works with several values collected on a
form. I thought it would be no problem, if the fields were empty,
because I made the function taking care of null-values.

Then I realized that I get an error when I try to pass the values like
that:

DatNext = A_Task_Next_Fct (Me![Task_ID],
Me![Task_Cycle],Me![Date_First, Me![Date_Last])

whenever one of the fields is empty.

What would be the correct way to handle this?

Thanks in advance.

Uwe

Nov 12 '05 #4
Neil,
He doesn't say the function accepts nulls, he says the function takes care
of nulls. The first is a subset of the second.

--
Terry Kreft
MVP Microsoft Access

"NeilAnders on" <ne***********@ boroughmuir.edi n.sch.uk> wrote in message
news:83******** *************** ***@posting.goo gle.com...
Uwe

You say that the function accepts nulls as parameters are you sure?
you haven't written it like A_Task_Next_Fct (myTask as long etc. etc)
If you are sure that it accepts nulls then is this what you are you
passing?
Does me![TaskID] default to 0 for instance?
It would help to know what the function does, what the error message
is & what line of code causes the error.

Neil
ur****@gmx.de (Uwe Range) wrote in message

news:<64******* *************** ****@posting.go ogle.com>...
Hi to all,

just ran into a problem:
I wrote a function which works with several values collected on a
form. I thought it would be no problem, if the fields were empty,
because I made the function taking care of null-values.

Then I realized that I get an error when I try to pass the values like
that:

DatNext = A_Task_Next_Fct (Me![Task_ID],
Me![Task_Cycle],Me![Date_First, Me![Date_Last])

whenever one of the fields is empty.

What would be the correct way to handle this?

Thanks in advance.

Uwe

Nov 12 '05 #5
First of all thanks for the response to all.

I think I didn't explain it properly: The function does not accept
null values when they are passed to it. I can only handle null values
within the function (by checking with 'if not IsNull(myTask_i d) ...').

Maybe Terry's suggestion to declare the variables as variant will
solve the problem. Otherwise I will have to test each value for null
values before passing it to the function and replace it with 0,
#1/1/1900#, "", ... which I would like to avoid.

Thanks again.

Uwe
ne***********@b oroughmuir.edin .sch.uk (NeilAnderson) wrote in message news:<83******* *************** ****@posting.go ogle.com>...
Uwe

You say that the function accepts nulls as parameters are you sure?
you haven't written it like A_Task_Next_Fct (myTask as long etc. etc)
If you are sure that it accepts nulls then is this what you are you
passing?
Does me![TaskID] default to 0 for instance?
It would help to know what the function does, what the error message
is & what line of code causes the error.

Neil
ur****@gmx.de (Uwe Range) wrote in message news:<64******* *************** ****@posting.go ogle.com>...
Hi to all,

just ran into a problem:
I wrote a function which works with several values collected on a
form. I thought it would be no problem, if the fields were empty,
because I made the function taking care of null-values.

Then I realized that I get an error when I try to pass the values like
that:

DatNext = A_Task_Next_Fct (Me![Task_ID],
Me![Task_Cycle],Me![Date_First, Me![Date_Last])

whenever one of the fields is empty.

What would be the correct way to handle this?

Thanks in advance.

Uwe

Nov 12 '05 #6
rkc

"Uwe Range" <ur****@gmx.d e> wrote in message
news:64******** *************** ***@posting.goo gle.com...
Hi to all,

just ran into a problem:
I wrote a function which works with several values collected on a
form. I thought it would be no problem, if the fields were empty,
because I made the function taking care of null-values.

Then I realized that I get an error when I try to pass the values like
that:

DatNext = A_Task_Next_Fct (Me![Task_ID],
Me![Task_Cycle],Me![Date_First, Me![Date_Last])

whenever one of the fields is empty.

What would be the correct way to handle this?


Correct way? I dunno.

A way, make the arguments optional and don't pass them if
they are null.


Nov 12 '05 #7
"Uwe Range" <ur****@gmx.d e> wrote in message
news:64******** *************** ***@posting.goo gle.com...
First of all thanks for the response to all.

I think I didn't explain it properly: The function does not accept
null values when they are passed to it. I can only handle null values
within the function (by checking with 'if not IsNull(myTask_i d) ...').

Maybe Terry's suggestion to declare the variables as variant will
solve the problem. Otherwise I will have to test each value for null
values before passing it to the function and replace it with 0,
#1/1/1900#, "", ... which I would like to avoid.


A common way to handle this is to coalesce the null to a known value having
the correct data type, e.g. zero for numeric types, which you can then test
for in the function. Use the Nz function.
Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2137
by: Ken Fine | last post by:
I have a menu system that has nodes that can be opened or closed. In an effort to make my code more manageable, I programmed a little widget tonight that keeps track of the open/active item and automatically builds querystrings for my redirect URLS. The code for this follows. It defines an ASP Dictionary object, and key/value pairs for each, and builds appropriate querystrings based on comparison with a status variable. The way it works...
5
7553
by: Yangang Bao | last post by:
I have a simple test program. It doesn't work. I want to know what is the reason and how to fix it. Maybe I should use template function to do it. But I don't know how. Here is the simple program. Strange enough that the problem never happens in C languge, i.e., in the program, if I call "foo2", it works fine. Why "foo1" doesn't work? Thanks for your answers.
6
1594
by: _andrea.l | last post by:
I'd like to write a function like: function f(){ ... bla ...} f_example(f); function f_example($function_to_execute) {...bla... $function_to_execute() ...bla....} AND how to pass the variable of the function :
2
2512
by: Ronnie Smith | last post by:
I am trying to pass a function (method) address to a user control to associate with an event. The small user control which sends events is contained in a larger user control group which is in turn contained in the main application. I need the event handler to exist at this top level in the application, and so I'm trying to somehow let the small control (two layers down) know the address of this handler, so that the function is called. ...
5
1785
by: D. Shane Fowlkes | last post by:
This may be a very basic question but it's something I've never done before. I've looked at a couple of my favorite sites and books and can't find an answer either. I can write a Function to return a single value. No big deal. But I want to call a Function from another Sub and the function finds and returns an entire db record. Using ASP.NET (VB!), how can this be done and how can I differentiate between the fields/columns? For...
6
2415
by: Minfu Lu | last post by:
I have a problem dealing with passing a function address to a COM callback. I use this COM function for communicating to a hardware. My original project was written in VB. I have converted it to C#. One of the problem is passing a function address to a COM function as a parameter with another progress value. My callback function is very simple using the progress value to update my progressbar. Because this COM function usually takes a long...
4
164187
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: session_set_save_handler(array(&$sess_handler, 'open'), array(&$sess_handler, 'close'), array(&$sess_handler, 'read'), array(&$sess_handler, 'write'), array(&$sess_handler, 'destroy'), array(&$sess_handler, 'gc'));
8
2351
by: laredotornado | last post by:
Hi, I want to pass my function myFunc('a', 'b', 'c') as an argument to another function. However, this will not work doStuff('x', 'y', myFunc('a', 'b', 'c'))
1
1682
by: shalini jain | last post by:
Hi, I am facing the problem with eval function. I want to know how to pass a function in eval() when we have to create the function itself. I would better explain my problem with the help of an example: For example Suppose there is function in someother file- test(54) Now i have 2 variables which independently contain the following values. i need to create that same function.
10
2215
by: iskhan | last post by:
Is it possible that pass a function name as a argument in an other function? e.g. MainMenu($SubMenu) { //Main menu designing start if(.......&&......||.......&&.......) { $this->$Submenu; // different submenus
0
10546
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10337
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11602
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
12022
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10309
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8698
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7868
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
5416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.