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_password 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.cancelevent and cancel=true but cant sort this out p
please can someone help
thanks liam
7 3678
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,556
Expert Mod 16PB
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,556
Expert Mod 16PB
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,556
Expert Mod 16PB
No worries Liam. I'm glad it's sorted anyway.
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
|
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: 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: 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...
| |