473,770 Members | 2,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Opening form after error

72 New Member
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
Expand|Select|Wrap|Line Numbers
  1.   DoCmd.OpenForm "frmCSN"
  2.  
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. If Err Then Cancel = True
  3. End Sub
  4.  
May 2 '07 #21
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.
May 2 '07 #22
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?
May 2 '07 #23
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.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Private Sub Form_Error(DataErr As Integer, Response As Integer)
  4. Call myBad
  5. End Sub
  6.  
  7. Private Sub Form_Open(Cancel As Integer)
  8. If Err Then Cancel = True
  9. End Sub
  10.  
  11. Sub myBad()
  12. MsgBox "Darn It"
  13. End Sub
  14.  

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.
May 2 '07 #24
smiler2505
72 New Member
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.
May 2 '07 #25
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.
May 2 '07 #26
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?
May 2 '07 #27
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 :)
May 2 '07 #28
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
Expand|Select|Wrap|Line Numbers
  1.   DoCmd.OpenForm "frmCSN"
  2.  
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:
  1. Create an AutoExec Macro and have it call a Public Function, in this case it would be fCheckForfrmCSN ().
  2. 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.
  3. The value of blnTableFound is next examined: if it is True, meaning tblCwS does exist, frmCSN is simply opened.
  4. If blnTableFound = False, meaning tblCwS does not exist, the Public Sub-Routine Rebuild_Test_Ta ble is called, then frmCSN is opened.
  5. 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.
  6. 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:
Expand|Select|Wrap|Line Numbers
  1. Public Function fCheckForFormCSN()
  2. Dim MyDB As DAO.Database, Mytdf As DAO.TableDef
  3. Dim blnTableFound As Boolean
  4.  
  5. blnTableFound = False
  6.  
  7. Set MyDB = CurrentDb()
  8.  
  9. For Each Mytdf In MyDB.TableDefs
  10.   If Mytdf.Name = "tblCwS" Then
  11.     blnTableFound = True
  12.      Exit For
  13.   Else
  14.   End If
  15. Next
  16.  
  17. If blnTableFound Then
  18.   DoCmd.OpenForm "frmCSN", acNormal, , , acFormEdit, acWindowNormal
  19. Else
  20.   Call Rebuild_Test_Table
  21.   DoCmd.OpenForm "frmCSN", acNormal, , , acFormEdit, acWindowNormal
  22. End If
  23. End Function
  24.  
May 3 '07 #29
smiler2505
72 New Member
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!
May 3 '07 #30

Sign in to post your reply or Sign up for a free account.

Similar topics

9
3114
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
5
9863
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...
3
2031
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
3
2127
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...
10
1639
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
3
9182
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...
3
8230
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 /...
1
1683
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...
6
2906
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...
9
2320
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...
0
9592
marktang
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...
0
10230
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
10058
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 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...
1
10004
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,...
0
9870
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...
0
5313
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
3972
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
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
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.