I am struggling with something that is probably quite simple. When I close a form, if certain fields are left empty then I want a message to pop up to tell the user these fields are required and then they can go back and fill them in.
Below is the code (which I found and modified slightly) and it works when used to check ONE field but when I added code for an additional field to be checked, it returns an error (run-time error 2450) - Access can't find the form 'Frm_Case' referred to in a macro expression or Visual Basic code - Private Sub btnBack_Click()
-
If IsNull(Forms![Frm_Case]![Frm_Individual_Details].Form![Per_Referral_Date]) Then
-
If MsgBox("You must enter a referral date." & Chr(13) & Chr(10) & Chr(13) & Chr(10) & _
-
"Press 'OK' to return and enter a date.", _
-
vbOKOnly, "Referral Date Required") _
-
= vbOKOnly And Forms![Frm_Case]![Frm_Individual_Details].Form![Per_Referral_Date].SetFocus Then
-
End If
-
Else
-
DoCmd.Close
-
End If
-
-
If IsNull(Forms![Frm_Case]![Frm_Individual_Details].Form![cboReferredFrom]) Then
-
If MsgBox("You must specify where the client was referred from." & Chr(13) & Chr(10) & Chr(13) & Chr(10) & _
-
"Press 'OK' to return and select a referral service.", _
-
vbOKOnly, "Referred From Service Required") _
-
= vbOKOnly And Forms![Frm_Case]![Frm_Individual_Details].Form![cboReferredFrom].SetFocus Then
-
End If
-
Else
-
DoCmd.Close
-
End If
-
-
End Sub
I need to add code for one more field. Any pointers/help greatly appreciated!
15 16639 ADezii 8,834
Recognized Expert Expert
For the 2nd Test, your syntax is incorrect, namely vbOKOnly is not a valid MsgBox Result, and you cannot tack on the And condition: - If IsNull(Forms![Frm_Case]![Frm_Individual_Details].Form![cboReferredFrom]) Then
-
If MsgBox("You must specify where the client was referred from." & vbCrLf & vbCrLf & _
-
"Press 'OK' to return and select a referral service.", _
-
vbOKOnly, "Referred From Service Required") = vbOK Then
-
[Frm_Case]![Frm_Individual_Details].Form![cboReferredFrom].SetFocus
-
End If
-
Else
-
DoCmd.Close
-
End If
P.S. - This type code normally resides in the Form's BeforeUpdate() Event.
I'm a little confused - if vbOKOnly is not a valid MsgBox Result and And cannot be tacked onto the condition, why does it work in the first test and not the second?
Would it be wiser to move all of this code to the Form's BeforeUpdate() Event as per your suggestion?
ADezii 8,834
Recognized Expert Expert
I'm a little confused - if vbOKOnly is not a valid MsgBox Result and And cannot be tacked onto the condition, why does it work in the first test and not the second?
vbOKOnly is a MsgBox 'Argument' and evaluates to 0 while vbOK is a MsgBox Result and evaluates to 1. What you are doing is evaluating the Return results of the Msgbox Function and testing to see if it = 0 (vbOKOnly) which will always evaluate to False since 0 is not a valid Msgbox Result. You then tack on an And condition to evaluate the Result of the SetFocus Method which makes no sense to me. I could be looking at this from the wrong angle, see what other Members have to say.
Would it be wiser to move all of this code to the Form's BeforeUpdate() Event as per your suggestion?
I think so, but you may have to set the Cancel Argument to true in order to negate the Update of the Form.
Putting the code into the Before Update event of the Form returns an error message (2501) - the Close action was cancelled.
I tried to understand what you've explained in the post above but it went a bit over my head so I'm going to leave this for today and give it a look tomorrow with a clear head to see if I grasp it then.
Cheers!
Right, I've had a better look at this and have been looking at the BeforeUpdate of the form and found this code which I have used instead of the code previously posted (I also realised I was overcomplicatin g referencing the fields in the code!) - If Len(Me!cboReferredFrom & vbNullString) = 0 Then
-
MsgBox "Please select where the client was referred from"
-
Cancel = True
-
Me!cboReferredFrom.SetFocus
-
End If
The only problem is, the form still closes if the field is blank. I thought the 'Cancel = True' part would prevent that?
Does it have something to do with me having a button that is used to close the form (OnClick even of button) also?
Another point, the fields are all in a subform on a form. I've tried putting the BeforeUpdate code in the subform (which works but still closes the form) and the form (which does nothing).
Thank you!
Okay so, Cancel = True doesn't relate to the closing of the form. I've tried a few things from that link but the form is still closing after the MsgBox pops up asking for the field to be filled in!
Still struggling with this if anyone has any pointers!
ADezii 8,834
Recognized Expert Expert Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Batezz |
last post by:
I have created a form (below)
How do I stop it redirecting to another page (productsearchresults.php) when
form is submitted if both the fields are blank?
Any help appreciated.
Batezz
|
by: Itai |
last post by:
I have an aspx file named index.aspx which contains two ‘form'
sections, one that has the runat=server attribute (e.g From1) and one
which is a regular HTML form (e.g SignInForm).
I am trying to copy values from two INPUT controls that are located
within the Form1 section to hidden INPUT controls located in the
SignInForm and post the SignInForm form hidden controls values to a
different page (e.g login.aspx)
Problem is that after...
|
by: Mark McLellan |
last post by:
Dear all
Following the oft-repeated advice here and ciwas I have made my site
nearly 4.01 strict (working on it). There are some items on which I would
appreciate your advice:
1. Hidden fields
http://www.zoo.co.uk/~mmenterprises/contact.htm
I am using FormMail from Matt's Script Archive. The W3C validator
objected to the hidden fields unless I put, say, P round them. That gave
|
by: visionstate |
last post by:
Hi there,
I have a form which has 2 text boxes, a combo box and a sub form in it
(which reads from a query. The query reads from the table).
On load, I would like the fields in the text boxes and combo box to be
become blank. If I use the "" or 'null' instruction then this in turn
makes the corresponding field in the sub form blank which in turn makes
the query field blank and the table field blank!
If I then change the combo box option,...
|
by: sparks |
last post by:
I am trying to fix a database that someone did about 4 yrs ago in
access97.
The main table just contains demographics and is on the main form of
the database.
It has a subform on a tab that contains the other information.
it is set 1 to 1 in the relationships.
simplify if I can
| |
by: Mark Rae |
last post by:
Hi,
See the previous thread Request.Form abuse in this newsgroup...
I'm looking for a simple and efficient way to prevent people hijacking the
<formtags on my websites and using them to send spam. I would imagine
they're using the HttpWebRequest method for this.
Essentially, it would require a property on a WebForm that indicates whether
it is *only* for PostBack (true by default, but configurable), which would
|
by: Jan |
last post by:
Hi:
I've got the Error 3197 problem ("The Microsoft Jet database engine
stopped the process because you and another user are attempting to
change the same data at the same time.") in a client database. It
started appearing about a month ago and has gotten worse and worse.
The responses I saw when I searched on this topic talk about corruption
in a memo or OLE field, but there are none of those in this database. I
took a copy of the...
|
by: kabradley |
last post by:
Alrighty Guys and Gals, I have another question that I hope you all can help me with.
I have a report that uses a cross-tab query as its record source. This cross-tab query is getting all of its information from another query. That query, qryRpt, is pulling information from several different tables. One of these table is tblDistributions, a table that holds monthly distributions for a particular investment, and the second is tblDeduction, a...
|
by: briggal1 |
last post by:
Hi
I wonder if anyone can help.
I have a report in Access 2000, which works perfectly and displays all the information until I select a period where one, or more, of the fields is blank.
Example 1:
I run the report and select data from 05/04/06 to 04/04/08 and get the report no problem.
|
by: MikeB |
last post by:
I created a small website for a friend. On this website he has a
contact page where people can send him email. When I wrote this page I
checked some tutorial pages and they warned about certain precautions
to take to avoid spammers using the mail form to spam multiple
people.
I believe I did most of that, such as making sure that the header
fields does not include multiple addresses, etc.
Now it does seem some spammer has discovered...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |