473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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(Cancel 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!frmCriteria

Dim EmptyTable As Recordset
Set EmptyTable = db.OpenRecordset("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 4077
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******@oldrepublic.com> wrote in message
news:50**************************@posting.google.c om...
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(Cancel 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!frmCriteria

Dim EmptyTable As Recordset
Set EmptyTable = db.OpenRecordset("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.CancelEvent 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***************@newssvr23.news.prodigy.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******@oldrepublic.com> wrote in message
news:50**************************@posting.google.c om...
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(Cancel 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!frmCriteria

Dim EmptyTable As Recordset
Set EmptyTable = db.OpenRecordset("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
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
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...
25
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...
1
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...
8
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...
2
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...
4
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...
2
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...
10
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
jinu1996
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 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.