Hi
i am fairly new to vba and have a taxi booking database.
every time you book a job the cust_name field must be filled out and same if account job for account_ref and account_passwor d fields but everytime the message box appears and you select ok the form closes
does any body no of a solution the code for the ok button is:
how can i cancel the code after the error checking keeping the form open to make the changes
i have tried the docmd.canceleve nt and cancel=true but cant sort this out p
please can someone help
thanks liam
7 3708
How is the code being called? I assume it is the result of the clicking on a button somewhere. Is there any other code being executed as well? I don't see anything in the code you posted that would cause the form to close.
Sorry the code was being called here: - Private Sub cmdOK_Click()
-
ClickOKButton
-
-
DoCmd.Close
-
Form_Jobs.Requery
-
-
End Sub
I have put the error checking in this section and removed it from the job section.it now looks like this: - Private Sub cmdOK_Click()
-
-
'***Error checking
-
If IsNull(cust_name) Then
-
MsgBox "Customer Name Must Be Entered !", vbQuestion, "CustomerName"
-
cust_name.SetFocus
-
Exit Sub
-
ElseIf Len(cust_name) < 2 Then
-
MsgBox "Name must be minimum of 2 characters", vbQuestion, "Customer Name"
-
cust_name.SetFocus
-
Exit Sub
-
ElseIf cboCashAccount = "Account" Then
-
If IsNull(account_reference) Then
-
MsgBox "Account reference must be entered because this is an account job", vbQuestion, "Account Reference"
-
account_reference.SetFocus
-
Exit Sub
-
ElseIf cboCashAccount = "Account" Then
-
If IsNull(account_password) Then
-
MsgBox "Account password must be entered because this is an account job", vbQuestion, "Account Password"
-
account_password.SetFocus
-
Exit Sub
-
End If
-
End If
-
End If
-
'***Error checking end
-
ClickOKButton
-
-
DoCmd.Close
-
Form_Jobs.Requery
-
-
End Sub
It has sorted the problem i had the form now stays open bit of a strange one really.
thanks for your help
liam
NeoPa 32,579
Recognized Expert Moderator MVP
I can't see how this code would produce the result you describe. Are you simply clicking on an OK button on your form? Or is something else going on we're not told about?
You may want to look at Debugging in VBA to see if you can narrow down where we should be looking for the problem.
NeoPa 32,579
Recognized Expert Moderator MVP
Ah. It seems we overlapped in our posts.
From that information it's quite obvious what the problem was. You call ClickOKButton then, regardless of the outcome, you close the form with DoCmd.Close. Hardly surprising that it closes then ;-)
Been stressing me out for a couple weeks now then its one of those problems you sit back and look at and you can see the problem
thanks again for all your inputs and help
liam
NeoPa 32,579
Recognized Expert Moderator MVP
No worries Liam. I'm glad it's sorted anyway.
Lysander 344
Recognized Expert Contributor
I use form validation code a lot and there is one other thing you might want to consider.
ATM, your code validates the form and either saves and closes if valid, or leaves the form open if invalid to correct.
All our data is entered by data-entry operators and if say, using your example, the account password is just not available, they have to close the form somehow, and move onto the next record.
All of our data entry forms have a button with the following code (titled 'Close without Saving') -
If Me.Dirty Then
-
If MsgBox(strTranslate("TR000000132", "Closing this form will lose all changes. Are you sure?"), vbYesNo) = vbYes Then
-
Me.Undo
-
DoCmd.Close
-
Else
-
Exit Sub
-
End If
-
Else
-
DoCmd.Close
-
End If
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Guy Robinson |
last post by:
I have the code below which parses an expression string and creates tokens.
Can anyone suggest the best of error checking for things like:
Valid variable only obj.attribute -whitespace allowed
test( "ff*2/dd.r..ss r") #additional ..ss -invalid variable.
test( "ff*$24..55/ddr") #double .. and $ -invalid number
test( "ff*2/dd.r.ss r") #variable with double . -invalid variable
|
by: Marc S. Gibian |
last post by:
I am putting together a Perl tool to manage a large set of tasks
related to building a rather complex set of software. One of the goals
for moving to Perl is to provide very rigorous error checking and
handling. One area that has me puzzled is error checking some of the
file system operations. Just simple things such as open, rename,
unlink, print and some others ... all the sample code I've seen uses
them in a form of:
open(...) || die...
|
by: Alistair |
last post by:
hey peoples.
I have a simple form (currently two fields) which is then passed to an ASP
page thats stores the data in a dbase
I have an error checking script which I can't get to work. the script is :
<script language="JavaScript">
|
by: khan |
last post by:
Hi guys,
I have a form called frminvoice, On this form I have a button to ptint
report or invoice where report will get invoice number from
!. Now I want when I click print invoice
button, it should close form frminvoice. this is the code I have. but
it is not closing the form.
On Error GoTo Err_Command18_Click
|
by: John S |
last post by:
When the user clicks the "X" in the upper right-hand corner of a form, how
can I stop the form from closing?
| |
by: **Developer** |
last post by:
I've been looking but can't find out how in a form Closing event to know if
the closing is because the form's "X" had been clicked or the main form's
"X" was clicked.
That is, I need to know if just the form is closing or the application is
closing.
Do you know how to tell?
|
by: lawrence k |
last post by:
I've made it habit to check all returns in my code, and usually, on
most projects, I'll have an error function that reports error messages
to some central location. I recently worked on a project where someone
suggested to me I was spending too much time writing error messages,
and that I was therefore missing the benefit of using a scripting
language. The idea, apparently, is that the PHP interpreter writes all
the error messages that are...
|
by: Mike |
last post by:
Hello,
Ok I have 2 classes in my project, one is the main form and one is a
connection class, at a certain event on my main form a new instance is
made of the connection class, and a reference to the main form is passed
to its constructor.
The connection class opens up a new thread and starts doing work in it,
and adds collected data to the main form via a (cross-thread) control
invoking delegate.
|
by: zacks |
last post by:
I have a .NET 2.0 MDI application where the child form has a Tab
Control. Each of the Tab in the Tab Control has a Validating event to
handle what it should do when the user changes tabs.
But these Validating Events are also fired when either the child form
or the main (parent) form Close icon is clicked. And I need for these
events to know if they are being invoked because the app (or child
window) is being closed. I have set a boolean...
|
by: Shoaibkhattak |
last post by:
Hy
when i define a new form and attach this form at a buuton on old form and debug the application.so when i open new form by clicking button new form opens and i close it by close button of control box.but when i try to open 2nd time that form it not open.and vb.net show error in show.newfor.
so i take a button in end of form and i code there me.hide.and false the control box.but i want if a person want to use close button on control box...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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...
| |