473,729 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I stop a form's open event in if there's an error?

Hi everyone,

As some of you may know, we've been having trouble with an
unrecognized database format error.

Today I installed an unfinished project on the workstation of one of
my users. It's a query by form in which she enters the criteria of
the record she wants in an unbound form, and it pulls only that record
and switches to the entry form so she can enter data. I had noticed
it was faster than find or filter, so I offered it to her even though
the other functions and features aren't done yet.

One of the things in this form is code in the Open event that opens an
empty table to stabilize the links to the back end. This code has
been in both my main forms, which are bound, for quite a while. When
I wrote it it didn't have any error handling code, but we never had
any trouble with it.

My user got the UDBF error while I was away from my desk, and when I
came back she also had a run-time error on the last line of the open
empty table code. This had never happened before on the other forms.
I tried entering error handling code, and this makes it generate a
message box when it can't connect to the database instead of a
run-time error.

So far so good, but then it opens the form anyway. I don't want it to
do that because it's confusing - I thought, "Oh, maybe it will still
work" - and if I think that, my users will also.

Does anyone know how I can stop the Open event and prevent it from
opening the form in case of an error? I tried the DoCmd.Close, but it
opens anyway.

Here is the code as I have it now:

Private Sub Form_Open(Cance l As Integer)
On Error GoTo Err_Form_Open

'Opens empty table to stay open while form is in use and improve
performance
'Closing of table not coded as .ldb file goes away when form is
closed.

Dim db As Database
Dim FormMe As Form

Set db = CurrentDB
Set FormMe = Forms!frmCriter ia

Dim EmptyTable As Recordset
Set EmptyTable = db.OpenRecordse t("tblEmpty", dbOpenDynaset,
dbOptimistic)

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Err.Description
DoCmd.Close acForm, FormMe, acSaveNo
Resume Exit_Form_Open

End Sub

Thanks for any help you can give!

Julia
Nov 13 '05 #1
2 4098
To stop the form from opening when there is an error place

Cancel = True

in the error handler for the Open event. Of course, this will only work on
errors that can be trapped in the Open event.

For information on corruption, these links may come in handy. You may have
seen these already, but just in case:
http://members.iinet.net.au/~allenbrowne/ser-25.html
http://members.iinet.net.au/~allenbrowne/ser-47.html

And on the UDBF error:
http://support.microsoft.com/default...roduct=acc2002
http://support.microsoft.com/default...22&Product=acc
--
Wayne Morgan
MS Access MVP
"Julia Baresch" <jb******@oldre public.com> wrote in message
news:50******** *************** ***@posting.goo gle.com...
Hi everyone,

As some of you may know, we've been having trouble with an
unrecognized database format error.

Today I installed an unfinished project on the workstation of one of
my users. It's a query by form in which she enters the criteria of
the record she wants in an unbound form, and it pulls only that record
and switches to the entry form so she can enter data. I had noticed
it was faster than find or filter, so I offered it to her even though
the other functions and features aren't done yet.

One of the things in this form is code in the Open event that opens an
empty table to stabilize the links to the back end. This code has
been in both my main forms, which are bound, for quite a while. When
I wrote it it didn't have any error handling code, but we never had
any trouble with it.

My user got the UDBF error while I was away from my desk, and when I
came back she also had a run-time error on the last line of the open
empty table code. This had never happened before on the other forms.
I tried entering error handling code, and this makes it generate a
message box when it can't connect to the database instead of a
run-time error.

So far so good, but then it opens the form anyway. I don't want it to
do that because it's confusing - I thought, "Oh, maybe it will still
work" - and if I think that, my users will also.

Does anyone know how I can stop the Open event and prevent it from
opening the form in case of an error? I tried the DoCmd.Close, but it
opens anyway.

Here is the code as I have it now:

Private Sub Form_Open(Cance l As Integer)
On Error GoTo Err_Form_Open

'Opens empty table to stay open while form is in use and improve
performance
'Closing of table not coded as .ldb file goes away when form is
closed.

Dim db As Database
Dim FormMe As Form

Set db = CurrentDB
Set FormMe = Forms!frmCriter ia

Dim EmptyTable As Recordset
Set EmptyTable = db.OpenRecordse t("tblEmpty", dbOpenDynaset,
dbOptimistic)

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Err.Description
DoCmd.Close acForm, FormMe, acSaveNo
Resume Exit_Form_Open

End Sub

Thanks for any help you can give!

Julia

Nov 13 '05 #2
Thanks Wayne! I tried Cancel = True and it worked beautifully. After
I posted this yesterday I found the DoCmd.CancelEve nt and used that,
but it generated a second message something like "you have cancelled
an event..." The Cancel = True doesn't do that, so it's a better
solution.

This is one of those things that so simple it's not in the
documentation.. .

Thanks also for the links. I hadn't seen the MS articles before, and
the one about the Visual Studio service pack might turn out to be what
we need. :-)

Julia

"Wayne Morgan" <co************ *************** @hotmail.com> wrote in message news:<%l******* ********@newssv r23.news.prodig y.com>...
To stop the form from opening when there is an error place

Cancel = True

in the error handler for the Open event. Of course, this will only work on
errors that can be trapped in the Open event.

For information on corruption, these links may come in handy. You may have
seen these already, but just in case:
http://members.iinet.net.au/~allenbrowne/ser-25.html
http://members.iinet.net.au/~allenbrowne/ser-47.html

And on the UDBF error:
http://support.microsoft.com/default...roduct=acc2002
http://support.microsoft.com/default...22&Product=acc
--
Wayne Morgan
MS Access MVP
"Julia Baresch" <jb******@oldre public.com> wrote in message
news:50******** *************** ***@posting.goo gle.com...
Hi everyone,

As some of you may know, we've been having trouble with an
unrecognized database format error.

Today I installed an unfinished project on the workstation of one of
my users. It's a query by form in which she enters the criteria of
the record she wants in an unbound form, and it pulls only that record
and switches to the entry form so she can enter data. I had noticed
it was faster than find or filter, so I offered it to her even though
the other functions and features aren't done yet.

One of the things in this form is code in the Open event that opens an
empty table to stabilize the links to the back end. This code has
been in both my main forms, which are bound, for quite a while. When
I wrote it it didn't have any error handling code, but we never had
any trouble with it.

My user got the UDBF error while I was away from my desk, and when I
came back she also had a run-time error on the last line of the open
empty table code. This had never happened before on the other forms.
I tried entering error handling code, and this makes it generate a
message box when it can't connect to the database instead of a
run-time error.

So far so good, but then it opens the form anyway. I don't want it to
do that because it's confusing - I thought, "Oh, maybe it will still
work" - and if I think that, my users will also.

Does anyone know how I can stop the Open event and prevent it from
opening the form in case of an error? I tried the DoCmd.Close, but it
opens anyway.

Here is the code as I have it now:

Private Sub Form_Open(Cance l As Integer)
On Error GoTo Err_Form_Open

'Opens empty table to stay open while form is in use and improve
performance
'Closing of table not coded as .ldb file goes away when form is
closed.

Dim db As Database
Dim FormMe As Form

Set db = CurrentDB
Set FormMe = Forms!frmCriter ia

Dim EmptyTable As Recordset
Set EmptyTable = db.OpenRecordse t("tblEmpty", dbOpenDynaset,
dbOptimistic)

Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Err.Description
DoCmd.Close acForm, FormMe, acSaveNo
Resume Exit_Form_Open

End Sub

Thanks for any help you can give!

Julia

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
11663
by: Baffin Shea | last post by:
Dear All, I am a beginner in javascript and looking for help, I put the following script in the original.asp: function NewWindows() { window.open("abc.asp", "new") }
15
4658
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any field to start. If I edit that field and then click on the new record button in the navigation buttons, the form goes to a new record and each field has the default value of the previous record. If I put the focus in any field to start, edit that...
25
10256
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the data in each record, which includes the ID of the father and the mother (who also have records in the table). One record per form. I have a Tab Control in the form, and in one of the tabs I have a subform (sfmSiblings) in which I wish to list...
1
2247
by: magic man via .NET 247 | last post by:
hi everyone i have a c# application that uses multithreading toconnect to sql server and execute a stored procedure on theserver. i am using a dataset,sqlcommand,dataadapter and adatagrid to carry out the process on a background thread andeverything goes well but the problem arrises when i created astop button that attempts to cancel the operation of datasetfilling(somtimes the query takes much time and i need to cancelthe operation) so that...
8
3518
by: Matt Theule | last post by:
While stepping through an ASP.NET project, I found that data was being inserted into my database even though I was not stepping through the code that inserted the data. I have a single page with inline code. The page has a Datagrid, a textbox and a button. When the button is clicked, the value of the textbox is inserted into the table whose contents are displayed on the page. The problem occurs when I set a breakpoint on a line *IN*...
2
4001
by: Martyn Fewtrell | last post by:
Dear All I have a Windows 2003 Server with IIS6 where the validation controls on ASP.Net pages no longer work. I believe it to be specific to the server as if I create an ASP.Net page on the IIS Server of my Workstation (Win XP) with a text box, button and required field validator, this works fine. If I create the same page on the IIS6 Windows 2003 Server the validation control doesn't stop the post. I've tried different browsers and...
4
2512
by: zack | last post by:
Any help with this would be greatly appreciated, as cannot work out how to resolve. I have a report called "3_Strikes". In its 'On open' event is command to also open a criteria form popup form called, "3_Strikes_Search". The purpose of the form is to allow input of data to filter the results of the report, (In this case mail-merged letters). The issue I have is that when I open the report via a command button, the "3_Strikes_Search"...
2
3206
by: kev | last post by:
Hi Folks, I have created a search query in which it successfully returns correct results. When there are no records returned, instead of giving out a blank form i created a pop-up msg which is attached to the On Open event. However, right after the msg box pops saying"no records", this is followed by another msg box with "TheOpen Form action was cancelled". Is there a way i can eliminate the second msg box from appearing?
10
15328
by: sara | last post by:
Hi - I have been struggling with solution ideas for this now for almost 2 weeks, and have not been able to figure this out. I have a user who creates a Purchase Order (tblPOData). In some circumstances, this or another user must create an invoice to go with the PO (I know - that makes no sense, but this is the business case). I have the user go to a form to create the invoice:
0
8767
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,...
0
9428
Oralloy
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...
0
9162
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
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...
0
6028
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4536
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...
1
3246
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
2
2701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2171
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.