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 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
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
"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/
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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"...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
by: Jess |
last post by:
Hello,
I tried a program as follows:
include<iostream>
using namespace std;
class A{
public:
|
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...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
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,...
|
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,...
|
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...
| |