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

check for null in module??

I have this code to run in a form button OnClick event to make sure the
start and end dates for reports have been entered, in case the end user
goes right to the buttons without typing any dates, in which case the
before/after update events don't work.

Public Function CheckDateEntry(dtmFirstDay As Date, dtmLastDay As Date)
'If IsNull(dtmFirstDay) = True Or dtmFirstDay = "" Or Len(dtmFirstDay)
= 0 Or IsNull(dtmLastDay) = True Or dtmLastDay = "" Or Len(dtmLastDay)
= 0 Then
If Nz(dtmFirstDay, "") = "" Or Len(dtmFirstDay) = 0 Or Nz(dtmLastDay,
"") = "" Or Len(dtmLastDay) = 0 Then
CheckDateEntry = True
Call MsgBox("Please enter the start and end dates for this
report.", vbExclamation Or vbSystemModal, "Required Data Entry")
Else
CheckDateEntry = False
End If
End Function

In the button OnClick code, this is called as
If CheckDataEntry (Me.dtmStartDate1, Me.dtmEndDate1) = False then
do the report printing
End If

Neither of the above checks works -- I constantly get error 94, invalid
use of null.

Have I written something incorrectly??

I have 5 tabs with 6 buttons each, all referencing start/end date on
the tabs, I would like some quick/reusable way to validate the
start/end dates.

Thank you, Tom

Jun 23 '06 #1
4 3825
The only VBA data type that can be Null is the Variant.
Trying to assign a Null value to a variable of type Date will fail.
Therefore the function fails on the very first line.

Since it must accept nulls, change it to:
Public Function CheckDateEntry(varFirstDay As Variant, varLastDay As
Variant)

I did not test the rest of your code, but you will probaby want to call it
with:
If Not CheckDataEntry (Me.dtmStartDate1.Value, Me.dtmEndDate1.Value)
Then
If you don't explicitly pass the value, the entire text box gets passed into
the function, i.e. varFirstDay will be an object of type TextBox.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"tlyczko" <tl*****@gmail.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
I have this code to run in a form button OnClick event to make sure the
start and end dates for reports have been entered, in case the end user
goes right to the buttons without typing any dates, in which case the
before/after update events don't work.

Public Function CheckDateEntry(dtmFirstDay As Date, dtmLastDay As Date)
'If IsNull(dtmFirstDay) = True Or dtmFirstDay = "" Or Len(dtmFirstDay)
= 0 Or IsNull(dtmLastDay) = True Or dtmLastDay = "" Or Len(dtmLastDay)
= 0 Then
If Nz(dtmFirstDay, "") = "" Or Len(dtmFirstDay) = 0 Or Nz(dtmLastDay,
"") = "" Or Len(dtmLastDay) = 0 Then
CheckDateEntry = True
Call MsgBox("Please enter the start and end dates for this
report.", vbExclamation Or vbSystemModal, "Required Data Entry")
Else
CheckDateEntry = False
End If
End Function

In the button OnClick code, this is called as
If CheckDataEntry (Me.dtmStartDate1, Me.dtmEndDate1) = False then
do the report printing
End If

Neither of the above checks works -- I constantly get error 94, invalid
use of null.

Have I written something incorrectly??

I have 5 tabs with 6 buttons each, all referencing start/end date on
the tabs, I would like some quick/reusable way to validate the
start/end dates.

Thank you, Tom

Jun 23 '06 #2
Ohhhhhhhhhhhhh...you are a genius. Thank you. :) :) :) :)

I did not know this about VBA programming etc. and this will be
something new that I have learned.

Thank you also for the extra tip on the Value property.

Thank you, :) tom

Allen Browne wrote:
The only VBA data type that can be Null is the Variant.
Trying to assign a Null value to a variable of type Date will fail.
Therefore the function fails on the very first line.

Since it must accept nulls, change it to:
Public Function CheckDateEntry(varFirstDay As Variant, varLastDay As
Variant)

I did not test the rest of your code, but you will probaby want to call it
with:
If Not CheckDataEntry (Me.dtmStartDate1.Value, Me.dtmEndDate1.Value)
Then
If you don't explicitly pass the value, the entire text box gets passed into
the function, i.e. varFirstDay will be an object of type TextBox.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"tlyczko" <tl*****@gmail.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
I have this code to run in a form button OnClick event to make sure the
start and end dates for reports have been entered, in case the end user
goes right to the buttons without typing any dates, in which case the
before/after update events don't work.

Public Function CheckDateEntry(dtmFirstDay As Date, dtmLastDay As Date)
'If IsNull(dtmFirstDay) = True Or dtmFirstDay = "" Or Len(dtmFirstDay)
= 0 Or IsNull(dtmLastDay) = True Or dtmLastDay = "" Or Len(dtmLastDay)
= 0 Then
If Nz(dtmFirstDay, "") = "" Or Len(dtmFirstDay) = 0 Or Nz(dtmLastDay,
"") = "" Or Len(dtmLastDay) = 0 Then
CheckDateEntry = True
Call MsgBox("Please enter the start and end dates for this
report.", vbExclamation Or vbSystemModal, "Required Data Entry")
Else
CheckDateEntry = False
End If
End Function

In the button OnClick code, this is called as
If CheckDataEntry (Me.dtmStartDate1, Me.dtmEndDate1) = False then
do the report printing
End If

Neither of the above checks works -- I constantly get error 94, invalid
use of null.

Have I written something incorrectly??

I have 5 tabs with 6 buttons each, all referencing start/end date on
the tabs, I would like some quick/reusable way to validate the
start/end dates.

Thank you, Tom


Jun 23 '06 #3
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in
news:44**********************@per-qv1-newsreader-01.iinet.net.au:
Since it must accept nulls, change it to:
Public Function CheckDateEntry(varFirstDay As Variant,
varLastDay As
Variant)

I did not test the rest of your code, but you will probaby want to
call it with:
If Not CheckDataEntry (Me.dtmStartDate1.Value,
Me.dtmEndDate1.Value)
Then
If you don't explicitly pass the value, the entire text box gets
passed into the function, i.e. varFirstDay will be an object of
type TextBox.


That's not strictly true. It's only a ByRef/ByVal issue. If you pass
the .Value, it is going to be an implicit ByVal, but if you do it
without the explicit .Value property, it will be ByRef. You can
avoid needing to specify .Value every time you pass values by simply
making the function definition into:

Public Function CheckDateEntry(ByVal varFirstDay As Variant, _
ByVal varLastDay As Variant)

I'm not certain it matters, though.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jun 23 '06 #4
Great.

This might help you avoid other issues also:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"tlyczko" <tl*****@gmail.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
Ohhhhhhhhhhhhh...you are a genius. Thank you. :) :) :) :)

I did not know this about VBA programming etc. and this will be
something new that I have learned.

Thank you also for the extra tip on the Value property.

Thank you, :) tom

Jun 24 '06 #5

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

Similar topics

1
by: Dmitry Martynov | last post by:
Hi I have a question whether XmlValidatingReader doesn't check keyref constrain (the same with key constraint) or I do smth wrong. I have the following schema <?xml version="1.0"...
7
by: Shaldaman | last post by:
Hi Is there a property in MS Access for the following: 1) For a Command Button on a form, is there a property that can be used to determine if it has been clicked? eg: Me!button7.Clicked - I...
5
by: Mats Larsson | last post by:
Hi, I have an example in C# for testing if a handler has been assigned to the delegate, I would like to do the same in VB.NET but I don't understand how. The C# code is copied from the Northwind...
21
by: sanjaymeher | last post by:
Hi, Right now addDynamicMemory(char **ptr, int size) method can able to handle if input ptr is intitialized to NULL or something. But how to improve this method to handle uninitialized pointed...
3
by: ferg | last post by:
I have a Customer table. The table has two different CHECK constraints. Then there is the Customer details dialog, which provides the user with an UI for changing users. I have some UPDATE sql,...
18
by: Joel Hedlund | last post by:
Hi! The question of type checking/enforcing has bothered me for a while, and since this newsgroup has a wealth of competence subscribed to it, I figured this would be a great way of learning...
30
by: Jess | last post by:
Hello, I tried a program as follows: include<iostream> using namespace std; class A{ public:
13
by: PhpCool | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the...
1
by: Anuj | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.