function module

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am a newbie working with Access coding. I created a module that is working
correctly I just want to add an If..then..Else statement, where the Else
would run the module...it goes something like this:
If checkbox = Null
then BillingCode = 90999
Else RunCode

Is this idea even close? Please help...thanks so much
 
Pretty close Lilla,

the syntax is like this:

If <condition> Then
<statement(s)>

Else If <condition> Then
<statement(s)

Else
<statement(s)>

End If

Cheers

John Webb
 
Lilia54 said:
I am a newbie working with Access coding. I created a module that is working
correctly I just want to add an If..then..Else statement, where the Else
would run the module...it goes something like this:
If checkbox = Null
then BillingCode = 90999
Else RunCode

Is this idea even close? Please help...thanks so much


Close, but it's it important for you to be aware that Null
is very special. One way of explaining it is that Null
means the value is unknown. This would imply that there is
no such thing as a meaninful comparison of anything with
Null, not even another Null. I.e. what does it mean to ask
if an unknown value is the same as as a known (or even
unknown) value? The only thing that makes sense is to ask
if the value is unknown. Access provides a built-in
function, IsNull, just for checking for this condition.

If IsNull(checkbox) Then
BillingCode = 90999
Else
RunCode
End If
 
Thank you so much for helping me....do you think it is better to use
something else with with the checkbox, like True or False?...instead of Null.
So I should code something like:
If checkbox = False (not checked)
Then billingcode = 90999
Else RunCode (it will run my other module)

Best,
Lily
 
If the check box is bound to a Yes/No field then check for
False. If the check box is bound to a numberic type field,
then you should check for both Null and False:

If NZ(checkbox, False) = False THen
. . .

If the check box is unbound and it has its TripleState
property set to Yes, then the same as above.

Because this can be confusing, I think it would be
appropriate to use the above check in all situations.
 
The checkbox is bound to a yes/no field, so I tried this:
Function CompCode (Wk4)
If Wk4 = False Then
CompCode = "90999"
ElseIf Wk4 = True Then
RunCode
End If
End Function

However the code is not working, I am getting undefined function error. I
think I do not have the RunCode correct. I think I need to define RunCode,
but I am not sure how to do it. The RunCode should run another module. I
defined RunCode in a Macro with the function module name.
Thank you so much for your help.
Lilia


Marshall Barton said:
If the check box is bound to a Yes/No field then check for
False. If the check box is bound to a numberic type field,
then you should check for both Null and False:

If NZ(checkbox, False) = False THen
. . .

If the check box is unbound and it has its TripleState
property set to Yes, then the same as above.

Because this can be confusing, I think it would be
appropriate to use the above check in all situations.
--
Marsh
MVP [MS Access]

Thank you so much for helping me....do you think it is better to use
something else with with the checkbox, like True or False?...instead of Null.
So I should code something like:
If checkbox = False (not checked)
Then billingcode = 90999
Else RunCode (it will run my other module)
 
Lilia54 said:
The checkbox is bound to a yes/no field, so I tried this:
Function CompCode (Wk4)
If Wk4 = False Then
CompCode = "90999"
ElseIf Wk4 = True Then
RunCode
End If
End Function

However the code is not working, I am getting undefined function error. I
think I do not have the RunCode correct. I think I need to define RunCode,
but I am not sure how to do it. The RunCode should run another module. I
defined RunCode in a Macro with the function module name.


Use the name of the Sub procedure instead of RunCode.

You do not run a module, which is just a container for
Function and Sub procedures, you can call a function in a
module by using the function in a expression such as:

A = 2 * myfunction(arglist) + 3

you can call a Sub procedure in either of two ways:

mysub arglist
or
Call mysub(arglist)

BTW, there is no need for you to use ElseIf Wk4 = True when
Wk4 is a YesNo field. Since a YesNo field can only be True
or False, simple Else is adequate.
 
I feel like I am really close, but 'no cigar'...here is what I have now:

Function CompCode(Wk4, Day)
If Wk4 = False Then
CompCode = "90999"
Else
Call BillingCode(totalvisits, Day)
End If
End Function

But when I use it in a query, I get the error message of undefined function
for CompCode. Again, your help is very appreciated.
 
Where do you have CompCode? In an actual module, or in the code associated
with a form? It must be in a module.
 
Back
Top