I have a situation where there may be no table for a form; on error, the table is rebuilt and all is good; except to open the form, I have to click the form again. I tried
but nothing happens. I think its because the form is already open, with the Sub form_OnError. But if I try and close the form, it crashes access and I get asked to send an error report, because the code is running from the form presumably. So how do I get round it? I've tried another form, which if it isn't called from the error works fine. I've tried to run the close function from another sub, and another macro, but every time I try and close the form where the error occurs it fails
Apr 30 '07
42 3422 Denburt 1,356
Recognized Expert Top Contributor
I think you are really REALLY close.
The Load event occurs when a form is opened and its records are displayed.
The Open event occurs when a form is opened, but before the first record is displayed.
No records error on open:
Try this: -
Private Sub Form_Open(Cancel As Integer)
-
If Err Then Cancel = True
-
End Sub
-
Rabbit 12,516
Recognized Expert Moderator MVP
Try compiling the database. Debug > Compile
Also, if you go to a line of code and press F9, it inserts a break point. When the code is running, when it gets to that line it stops and the VBA editor opens and highlights that line. F8 let's you step through the code line by line as it executes. F5 continues execution without stopping.
I often use this when I can't figure out what's wrong with my code, it allows me to pause at each step and see what's going on. A neat feature is if you hover the cursor over a variable or control name, it tells you its current value.
MMcCarthy 14,534
Recognized Expert Moderator MVP
tried it. It still crashes :(.
Is there anyway to check if a form is doing something? I can only assume that I'm trying to close it too early; it opens, causes an error, and is caught in an endless loop. But we seem to have tried everything.
Try sticking a DoEvents command at the crisis point. In other words straight before the close form command. This should process all code prior to this point before attempting to close the form
Just out of curiousity have you any code in the Form Close event?
Denburt 1,356
Recognized Expert Top Contributor
I know you are getting flooded with things to try however I just created a form the following worked and hopefully might help. -
Option Compare Database
-
Option Explicit
-
Private Sub Form_Error(DataErr As Integer, Response As Integer)
-
Call myBad
-
End Sub
-
-
Private Sub Form_Open(Cancel As Integer)
-
If Err Then Cancel = True
-
End Sub
-
-
Sub myBad()
-
MsgBox "Darn It"
-
End Sub
-
Although I was unable to get the error message not to show everything else seemed to work. I am in a pinch got to go good luck and I will check back later. I hope some of this helps. :)
Oh and I put the sub myBad in both the form and in a separate module with no problem.
just tried the form open thing on its own, with form_onerror, with and without DoEvents...noth ing
It is definetly the DoCmd.Close acForm, "frmCSN" causing the error; without it there is no crash, but the one problem still remains, the form doesn't open automatically after the table has been recompiled.
Denburt 1,356
Recognized Expert Top Contributor
Utilizing the code in post 24 you will not need to close it, simply because it never opens and that is why you get an error if you are going to attempt to reopen it place you build table sub in a separate module follow Rabbits instructions (Post 22) and add the DoEvents as Mary suggested and it should work.
MMcCarthy 14,534
Recognized Expert Moderator MVP
just tried the form open thing on its own, with form_onerror, with and without DoEvents...noth ing
It is definetly the DoCmd.Close acForm, "frmCSN" causing the error; without it there is no crash, but the one problem still remains, the form doesn't open automatically after the table has been recompiled.
Did you try Nico's suggestion of checking to see if the table exists without opening the form at all?
Denburt 1,356
Recognized Expert Top Contributor
1 more before I go I just noticed nico's suggestion and it is a good one uh post 17 also when you click the button, or whatever event you use to open this form run his routine before even trying to open the form. If needed build it then open. Sounds like a good plan there.
LOL Mary got in when I wasn't looking :)
ADezii 8,834
Recognized Expert Expert
I have a situation where there may be no table for a form; on error, the table is rebuilt and all is good; except to open the form, I have to click the form again. I tried
but nothing happens. I think its because the form is already open, with the Sub form_OnError. But if I try and close the form, it crashes access and I get asked to send an error report, because the code is running from the form presumably. So how do I get round it? I've tried another form, which if it isn't called from the error works fine. I've tried to run the close function from another sub, and another macro, but every time I try and close the form where the error occurs it fails
I don't mean to over simplify matters, and I have only had a short glimpse at the code, but to me the answer seems fairly obvious. You cannot trap this Critical Error in the Form's Error() Event. The condition of the non-existant Table which is the Record Source for the Form should be checked as soon as the Database opens. I've scaled down your code and I have arrived at a solution, hopefully it is one which you can implement: - Create an AutoExec Macro and have it call a Public Function, in this case it would be fCheckForfrmCSN ().
- This Function will loop through the TableDefs Collection, and if it finds tblCwS, it sets a Boolean Variable (blnTableFound = True). This Variable is initially initialized to False though it need not be.
- The value of blnTableFound is next examined: if it is True, meaning tblCwS does exist, frmCSN is simply opened.
- If blnTableFound = False, meaning tblCwS does not exist, the Public Sub-Routine Rebuild_Test_Ta ble is called, then frmCSN is opened.
- Again, if I have oversimplified the problem or did not read enough into it I apologize, but the code below has been tested and is fully functional. Remember, I tested it on a scaled version of what you have displayed.
- Please let me know what you think - I'm very interested in seeing if this solution is acceptable.
Call from the AutoExec Macro, or from an Initial Display Form if more practical: - Public Function fCheckForFormCSN()
-
Dim MyDB As DAO.Database, Mytdf As DAO.TableDef
-
Dim blnTableFound As Boolean
-
-
blnTableFound = False
-
-
Set MyDB = CurrentDb()
-
-
For Each Mytdf In MyDB.TableDefs
-
If Mytdf.Name = "tblCwS" Then
-
blnTableFound = True
-
Exit For
-
Else
-
End If
-
Next
-
-
If blnTableFound Then
-
DoCmd.OpenForm "frmCSN", acNormal, , , acFormEdit, acWindowNormal
-
Else
-
Call Rebuild_Test_Table
-
DoCmd.OpenForm "frmCSN", acNormal, , , acFormEdit, acWindowNormal
-
End If
- End Function
-
Missed post 16, 17 last night. loads of responses and stuff to try out!
Going to try out Nico's idea, then play around with azii's and mary's idea
I'll be back in a few minutes!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: MLH |
last post by:
If you have these lines in code on MyForm1...
DoCmd OpenForm "MyForm2`"
MsgBox "I opened MyForm2"
Is it #ALWAYS# true that all form events
on MyForm2 will occur before the MsgBox
statement in MyForm1 is processed?
Is there ever an exception that might create
|
by: Lyn |
last post by:
Hi, this has been driving me nuts. I'm on Office 2003 SP1, Win XP SP1.
I am opening a form with a number of subforms based on various tables. The
subforms are populated via the main form's Current event. I am using
similar code to open each of the subforms successfully -- except for this
one case which gives the above error.
I have simplified the SQL to its most basic level. It runs just fine as a
query. I just can't make it work...
|
by: Jim Evans |
last post by:
Using code and suggestions from an earkier thread in this group, I have
created the following cond for the open event of a form I am opening from
the button click event of another form.
Private Sub Form_Open(Cancel As Integer)
If Len(Me.OpenArgs & "") > 0 Then
Dim i As Integer
Dim s As String
|
by: Rolan |
last post by:
I need assistance regarding code needed to prevent someone from opening
a form if a table field name(s) has been changed. For example, there is
existing code to check for certain data based on DLookup in a table
before a form can be opened. If one changes the field name in the
table, then the verification check is bypassed. So adding code to
DLookup to check for the existence of specific field names first is
necessary. Any insight will be...
|
by: Norm |
last post by:
I must not be understanding something about the use of forms in VB.Net that
is different from VB. I have one form running in the background with an icon
in the task bar. Right clicking on the icon gives you a list of options, one
of which is to show an About form. After this form shows I get an error
saying "Object reference not set to an instance of the object." I have tried
opening the form with
frmAbout.Show
frmAbout.ShowDialog
| |
by: MartinR |
last post by:
Hi,
I'm still new to writing code in vba as I've only been introduced to
access three weeks ago. I have written this code below and it executes
but does not do what I want it to do. What I want is the form
"Sparesform" to open when I double click on the "index" field for the
record I wish to view. The index field is part of a subform. What is
happening at the moment is the form "Sparesform" is opening but does
not go to the correct record...
|
by: frenchy |
last post by:
I am getting this error in Adobe after struggling with a 'submit'
button on an acrobat form that is in production and all the other
appdev people in the office are NOT having a problem with. It submits
the form to the web successfully for them, for me the button just
clicks and does nothing. So we turned on my javascript debug in Adobe
and are getting this?
Acrobat EScript Built-in Functions Version 6.0
Acrobat Annotations /...
|
by: Coll |
last post by:
I have a form with a subform on it. On my main form, you select an
employee id number and the top portion of form fills in with data, and
the bottom portion of the form,which is a subform, lists existing
records there are for that employee (one to many relationship). How
can I set up my main form, so the user can select one of the records
on the subform and retain that recordid number for use in opening a
new form and displaying the that...
|
by: martin DH |
last post by:
**Urgent Need**
I'll throw out the basics and any assistance is very, very, very much appreciated!
Access 2003 on XP
On a form (frmMain) is an option group of check boxes (ReportFrame) from which a user can choose a specific report to generate. The user selects the report of choice then presses a comand button (CmdRunRpt). The command button runs using the code below:
Private Sub CmdRunRpt_Click()
If ReportFrame = 1 Then...
|
by: angi35 |
last post by:
Hi - In Access 2000, I'm trying to create a switchboard so users can open a certain form with different filters. I thought I would use an option group with toggle buttons. I suppose it could be just a series of command buttons instead. Either way, I can't figure out the code to get Access to both open a form and filter it at the same time.
Part of my trouble is also that the terms I need to filter on are multiple words, and I'm really...
|
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: 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: 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...
|
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: 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: 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...
| |