473,320 Members | 1,987 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,320 software developers and data experts.

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 14683
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(MyParameter,"")). I hope someone with more experience responds...
Fred Zuckerman
San Diego, CA, USA
"Uwe Range" <ur****@gmx.de> wrote in message
news:64**************************@posting.google.c om...
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.de> wrote in message
news:64**************************@posting.google.c om...
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.google. 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

"NeilAnderson" <ne***********@boroughmuir.edin.sch.uk> wrote in message
news:83**************************@posting.google.c om...
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.google. 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_id) ...').

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***********@boroughmuir.edin.sch.uk (NeilAnderson) wrote in message news:<83**************************@posting.google. 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.google. 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.de> wrote in message
news:64**************************@posting.google.c om...
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.de> wrote in message
news:64**************************@posting.google.c om...
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_id) ...').

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
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...
5
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...
6
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...
2
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...
5
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...
6
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...
4
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: ...
8
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
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...
10
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;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.