I have a form with multiple textboxes and 2 command buttons (Save, Cancel).
If user clicks the CANCEL button, I would like to check if all the textboxes on that form are null and in the case they are, I wan't form to close immediately.
If all the textboxes are not null, I want to ask user if he really wants to cancel and warn him that all entered data will be lost.
When I run the code, I receive the runtime error 438.
My code is something like this: - Private Sub cmdWrite_Click()
-
-
Dim stDocName As String
-
Dim stLinkCriteria As String
-
Dim c As Control
-
Dim check As Boolean
-
-
stDocName = "START_M"
-
check = True
-
-
For Each c In Me.Controls
-
If TypeOf c Is TextBox And Not IsNull(c.value) Then check = False
-
Next
-
-
If check = False And funz_are_you_sure = "NO" Then Exit Sub
-
Else
-
DoCmd.Close
-
DoCmd.OpenForm stDocName, , , stLinkCriteria
Here comes the code of the function: - Public Function funz_are_you_sure() As String
-
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
-
Msg = "Are you sure? You will lose all inserted data..."
-
Style = vbYesNo + vbExclamation + vbDefaultButton2
-
Title = "Cancelling confirm"
-
Response = MsgBox(Msg, Style, Title)
-
If Response = vbYes Then
-
funz_are_you_sure = "YES"
-
Else
-
funz_are_you_sure = "NO"
-
End If
-
End Function
It's because I forgot to nest the If tests... - Dim ctl As Control
-
Dim booFilledBox As Boolean
-
-
For Each ctl In Me.Controls
-
If ctl.ControlType = acTextBox Then
-
If Not (IsNull(ctl.Value) Or ctl.Value ="") Then
-
booFilledBox = True
-
End If
-
End If
-
Next ctl
The problem with the way I wrote it out the first time is that Access evaluates the WHOLE line for each control. There are some controls that cannot have a value, and so ctl.Value has no meaning. As a result, we need to first check that the control is a text box (or some other control that can have a value, like a combo box) - then make the check to see if it's empty or not.
Pat
5 17344
What line are you getting the error on? You can check this by setting a breakpoint at the first executable line in the code and then stepping through it using F8.
Usually, when I do checks like this in my Access forms, I do something like this: - Dim ctl As Control
-
Dim booFilledBox As Boolean
-
-
For Each ctl In Me.Controls
-
If ctl.ControlType = acTextBox And Not (IsNull(ctl.Value) Or ctl.Value ="") Then
-
booFilledBox = True
-
End If
-
Next ctl
-
-
'Handle case for finding a filled text box...
Pat
Hi, tnx for answering.
I totally forgot to check the error with debugging.
I tried your code also and I get the same error number, it's on this line: - If ctl.ControlType = acTextBox And Not (IsNull(ctl.Value) Or ctl.Value ="") Then
acTextBox value is "109" - I guess it's standard numeric value for text box
ctl is null
And that's it, I still don't understand.
It's because I forgot to nest the If tests... - Dim ctl As Control
-
Dim booFilledBox As Boolean
-
-
For Each ctl In Me.Controls
-
If ctl.ControlType = acTextBox Then
-
If Not (IsNull(ctl.Value) Or ctl.Value ="") Then
-
booFilledBox = True
-
End If
-
End If
-
Next ctl
The problem with the way I wrote it out the first time is that Access evaluates the WHOLE line for each control. There are some controls that cannot have a value, and so ctl.Value has no meaning. As a result, we need to first check that the control is a text box (or some other control that can have a value, like a combo box) - then make the check to see if it's empty or not.
Pat
Wow. It works! :)
Interesting, the thing is that, as you can see, it also crossed my mind that not all controls have value property, so I added the code to check if the control is textbox, just as you did in your first code.
But I still don't understand completely, even if Access evaluates the whole line, our code included AND, so it would set boolean variable only in case both conditions are truth. So if the Access knows that one condition is not truth for sure (if it's not textbox), it shouldn't matter if it can't determine or process the second condition, becuase the boolean is in any case false.
Obviously, it does matter, but why?
UPDATE: Ooops, I think I kind of a answered myself. It's exactly beacuse of the AND that the machine looks at it as a WHOLE like you already pointed.
Well, thank you very much for your answer!
Well, the problem is that an expression which errors (such as ctl.Value for a ctl which cannot have a value) cannot be assigned a boolean status. So actually, the part after the AND has no boolean status and the entire line errors out.
Pat
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Shyguy |
last post by:
I have two forms that both open the same (3rd) form.
The third form does the same thing, but a little differently depending
on which form it is opened from. Is there a way I can check which
form...
|
by: Rich |
last post by:
I have a access form that is connected to linked sql table via odbc.
I have some fields that I dont want to allow nulls when data is
entered via the form. I can set the null checking on the SQL...
|
by: JIK |
last post by:
Hi.
I have a web app written in ASP.NET/C# with a lot of textboxes, dropdowns
etc.
Is there any possibilities to check for changes in texboxes etc in a web
form on the client side easily?
And...
|
by: Gene |
last post by:
As my purpose is to load one form at a time,
so I want to unload another form before loading the form.
But how to check which form is being load, so I can unload it first.
|
by: Eagle |
last post by:
Hi,
I've got an input form (frmInput) that can be accessed in two ways.
A combobox on this form either gets filled in by a selection on an already
opened form (frmBasic), or one can input a...
|
by: KelsMckin |
last post by:
Hello, I was wondering if there was a way to check there was already a
form open before opening a new one, sorry that doesnt seem clear, here
is an example:
The following button opens a new form...
|
by: News Microsoft |
last post by:
Hi there.
I would like to know how can I test if a Form exists.
This is the situation: I have a single Form in my application. My objective
is, when I minimize the form, it will disapear and a...
|
by: pamela fluente |
last post by:
I want a simple method or function to check if at least one of the
field in a composite object is null (nothing).
For instance, if Field5 is null I would like that a function such
as
...
|
by: wassimdaccache |
last post by:
Hello everybody
I'm using access 2003
Sometimes I use to open more than form in my project what I need is to check another form if still opened
For example I have :
form name X,Y,Z
|
by: cssExp |
last post by:
Hello,
It should be working but for some reasons it's not.
function Validator(frmname)
{
this.formobj=document.forms;
if(!this.formobj)
{
alert("BUG: couldnot get Form object...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
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...
| |