Opening form after error | Member | | Join Date: Apr 2007
Posts: 72
| |
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
| | Expert | | Join Date: Apr 2007
Posts: 192
| | | re: Opening form after error Quote:
Originally Posted by smiler2505 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 haven't tried this, but, if the form is already open, and having rebuilt the table within your error handling process, try me.requery or me.refresh so that the open form tries again to access your data
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
It opens in design mode the first time I edit the vba, but after that the result is the same. Click, and no form opens.
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,875
| | | re: Opening form after error
In the Sub form_OnError code add the line. - DoCmd.Close acForm, "frmCSN"
Mary
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error Quote:
Originally Posted by mmccarthy In the Sub form_OnError code add the line. - DoCmd.Close acForm, "frmCSN"
Mary I tried that but nothing happens (see first post) :(
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,875
| | | re: Opening form after error Quote:
Originally Posted by smiler2505 I tried that but nothing happens (see first post) :( In what event have you got the code checking if the table exists?
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
form on error. When I try and open the form without a table associated I get an error saying to effect the table does not exist. I think I tried it under form load, but I still got the error
The code is
If dataerr = (the error code) Then
Build Table
Response = acDataErrContinue
End If
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,875
| | | re: Opening form after error Quote:
Originally Posted by smiler2505 form on error. When I try and open the form without a table associated I get an error saying to effect the table does not exist. I think I tried it under form load, but I still got the error
The code is
If dataerr = (the error code) Then
Build Table
Response = acDataErrContinue
End If And where exactly did you put the form close in this code.
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
If dataerr = (the error code) Then
Build Table
[font=Arial]DoCmd.OpenForm "frmCSN"[/font]
Response = acDataErrContinue
End If
T'was at the end of the build table code. I also tried to launch another form and reopen frmCSN from there, without success.
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,875
| | | re: Opening form after error
You need to close the form. Then build the table and then open the form again but you can't do that in the Form_Error event because once you close the form the code is no longer in focus. -
Private Sub Form_Error()
-
-
If dataerr = (the error code) Then
-
call noTable
-
End If
-
-
End Sub
-
-
Sub noTable()
-
-
DoCmd.Close acForm, "frmCSN"
-
Build Table
-
DoCmd.OpenForm "frmCSN"
-
Response = acDataErrContinue ' not sure how to cater for this as you haven't given me that part of the code
-
-
End Sub
-
Mary
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
I still get the error
The code I have is: -
Private Sub Form_Error(DataErr As Integer, Response As Integer)
-
If DataErr = "2580" Then
-
-
Call FormFIX
-
-
End If
-
-
End Sub
-
Sub FormFIX()
-
-
DoCmd.Close acForm, "frmCSN", acSaveNo
-
-
-
-
-
DoCmd.SetWarnings False
-
-
On Error GoTo ExitCreateCwS
-
-
Dim daodb As DAO.Database
-
Dim daotdfCwS As DAO.TableDef
-
Dim daofldCNum As DAO.Field
-
Dim daofldSNum As DAO.Field
-
Dim daofldCCanEnt As DAO.Field
-
Dim fldCNum As Field
-
Dim fmtffCNum As Property
-
Dim daoidxCNum As DAO.Index
-
Dim daofldiCNum As DAO.Field
-
Dim fldSNum As Field
-
Dim fmtffSNum As Property
-
Dim daoidxSNum As DAO.Index
-
Dim daofldiSNum As DAO.Field
-
Dim fldCCanEnt As Field
-
Dim fmtffCCanEnt As Property
-
Dim daoidxCCanEnt As DAO.Index
-
Dim daofldiCCanEnt As DAO.Field
-
Dim tdfCen As TableDef
-
Dim relCen As Relation
-
Dim tdfSub As TableDef
-
Dim relSub As Relation
-
-
Set daodb = CurrentDb()
-
Set daotdfCwS = daodb.CreateTableDef("tblCwS")
-
-
-
-
Set daofldCNum = daotdfCwS.CreateField("CNum", dbLong)
-
-
daofldCNum.DefaultValue = "10000"
-
daofldCNum.ValidationRule = "Between 10000 And 79999 And Len([CNum])=5"
-
daofldCNum.ValidationText = "Must be 5 digits long, lie between 10000 and 79999, and unique"
-
daofldCNum.Required = True
-
-
-
Set daofldSNum = daotdfCwS.CreateField("SNum", dbText, 5)
-
-
daofldSNum.DefaultValue = "11111"
-
daofldSNum.ValidationRule = "Len([SNum])=5"
-
daofldSNum.ValidationText = "Must be 5 digits long"
-
daofldSNum.Required = True
-
daofldSNum.AllowZeroLength = False
-
-
-
Set daofldCCanEnt = daotdfCwS.CreateField("CCanEnt", dbLong)
-
-
daofldCCanEnt.DefaultValue = "0"
-
daofldCCanEnt.ValidationRule = ">=0"
-
daofldCCanEnt.ValidationText = "Please enter number of candidates"
-
daofldCCanEnt.Required = True
-
-
-
-
daotdfCwS.Fields.Append daofldCNum
-
daotdfCwS.Fields.Append daofldSNum
-
daotdfCwS.Fields.Append daofldCCanEnt
-
daodb.TableDefs.Append daotdfCwS
-
-
-
-
Set fldCNum = daotdfCwS.Fields("CNum")
-
-
Set fmtffCNum = fldCNum.CreateProperty("Format", dbText, "General Number")
-
fldCNum.Properties.Append fmtffCNum
-
Set fmtffCNum = fldCNum.CreateProperty("DecimalPlaces", dbByte, 0)
-
fldCNum.Properties.Append fmtffCNum
-
Set fmtffCNum = fldCNum.CreateProperty("InputMask", dbText, "00000")
-
fldCNum.Properties.Append fmtffCNum
-
Set fmtfCNum = fldCNum.CreateProperty("Caption", dbText, "Centre number")
-
fldCNum.Properties.Append fmtfCNum
-
Set fmtfCNum = fldCNum.CreateProperty("DisplayControl", dbInteger, 111)
-
fldCNum.Properties.Append fmtfCNum
-
Set fmtfCNum = fldCNum.CreateProperty("RowSource", dbText, "SELECT tblCen.CNum FROM tblCen;")
-
fldCNum.Properties.Append fmtfCNum
-
Set fmtfCNum = fldCNum.CreateProperty("ListRows", dbInteger, 255)
-
fldCNum.Properties.Append fmtfCNum
-
Set fmtfCNum = fldCNum.CreateProperty("LimitToList", dbBoolean, True)
-
fldCNum.Properties.Append fmtfCNum
-
-
Set daoidxCNum = daotdfCwS.CreateIndex("CNum")
-
-
daoidxCNum.Required = True
-
-
Set daofldiCNum = daoidxCNum.CreateField("CNum")
-
-
daoidxCNum.Fields.Append daofldiCNum
-
daotdfCwS.Indexes.Append daoidxCNum
-
-
-
Set fldSNum = daotdfCwS.Fields("SNum")
-
-
Set fmtfSNum = fldSNum.CreateProperty("InputMask", dbText, "00000")
-
fldSNum.Properties.Append fmtfSNum
-
Set fmtfSNum = fldSNum.CreateProperty("Caption", dbText, "Subject Reference Code")
-
fldSNum.Properties.Append fmtfSNum
-
Set fmtfSNum = fldSNum.CreateProperty("UnicodeCompression", dbBoolean, True)
-
fldSNum.Properties.Append fmtfSNum
-
Set fmtfSNum = fldSNum.CreateProperty("DisplayControl", dbInteger, 111)
-
fldSNum.Properties.Append fmtfSNum
-
Set fmtfSNum = fldSNum.CreateProperty("RowSource", dbText, "SELECT tblSub.SNum FROM tblSub;")
-
fldSNum.Properties.Append fmtfSNum
-
Set fmtfSNum = fldSNum.CreateProperty("ListRows", dbInteger, 255)
-
fldSNum.Properties.Append fmtfSNum
-
Set fmtfSNum = fldSNum.CreateProperty("LimitToList", dbBoolean, True)
-
fldSNum.Properties.Append fmtfSNum
-
-
Set daoidxSNum = daotdfCwS.CreateIndex("SNum")
-
-
daoidxSNum.Required = True
-
-
Set daofldiSNum = daoidxSNum.CreateField("SNum")
-
-
daoidxSNum.Fields.Append daofldiSNum
-
daotdfCwS.Indexes.Append daoidxSNum
-
-
-
Set fldCCanEnt = daotdfCwS.Fields("CCanEnt")
-
-
Set fmtfCCanEnt = fldCCanEnt.CreateProperty("Format", dbText, "General Number")
-
fldCCanEnt.Properties.Append fmtfCCanEnt
-
Set fmtfCCanEnt = fldCCanEnt.CreateProperty("DecimalPlaces", dbByte, 0)
-
fldCCanEnt.Properties.Append fmtfCCanEnt
-
Set fmtfCCanEnt = fldCCanEnt.CreateProperty("Caption", dbText, "N° of candidates entered")
-
fldCCanEnt.Properties.Append fmtfCCanEnt
-
-
Set daoidxCCanEnt = daotdfCwS.CreateIndex("CCanEnt")
-
-
daoidxCCanEnt.Required = True
-
-
Set daofldiCCanEnt = daoidxCCanEnt.CreateField("CCanEnt")
-
-
daoidxCCanEnt.Fields.Append daofldiCCanEnt
-
daotdfCwS.Indexes.Append daoidxCCanEnt
-
-
-
-
DoCmd.RunSQL "INSERT INTO tblCwS SELECT tblCen.CNum, tblSub.SNum FROM tblCen, tblSub;"
-
-
-
Set tdfCen = daodb.TableDefs!tblCen
-
Set relCen = daodb.CreateRelation("CenCwS", tdfCen.Name, daotdfCwS.Name, dbRelationUpdateCascade + dbRelationDeleteCascade)
-
-
relCen.Fields.Append relCen.CreateField("CNum")
-
relCen.Fields!CNum.ForeignName = "CNum"
-
daodb.Relations.Append relCen
-
-
-
Set tdfSub = daodb.TableDefs!tblSub
-
Set relSub = daodb.CreateRelation("SubCwS", tdfSub.Name, daotdfCwS.Name, dbRelationUpdateCascade + dbRelationDeleteCascade)
-
-
relSub.Fields.Append relSub.CreateField("SNum")
-
relSub.Fields!SNum.ForeignName = "SNum"
-
daodb.Relations.Append relSub
-
-
-
-
ExitCreateCwS:
-
-
-
-
DoCmd.OpenForm "frmCSN"
-
Response = acDataErrContinue
-
-
-
End Sub
-
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,875
| | | re: Opening form after error
Sorry take the sub FormFIX procedure out of the form code and put it in it's own module. Once the form closes the procedure is no longer available if it's in the Form code.
Mary
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
I already tried that.
I put it into a seperate module completely, and called that sub from the form that has to be closed. I still got the error. Is there anyway to stop a form from procesing anything?
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,875
| | | re: Opening form after error Quote:
Originally Posted by smiler2505 I already tried that.
I put it into a seperate module completely, and called that sub from the form that has to be closed. I still got the error. Is there anyway to stop a form from procesing anything? Take the call out of the form_error and put it in the on error section of the Form_Load event instead.
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
so...
Sub Form_Load(DataErr as Integer) 'or whatever the correct call is for form load
If DataErr = 2580 Then
'Build table
DoCmd.Open "frmCSN"
End If
End Sub
?
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,875
| | | re: Opening form after error
No -
Sub Form_Load()
-
On Error Go To Err_Form_Load
-
-
' your code here
-
-
Err_Form_Load:
-
Select Case Err
-
Case 0
-
Resume Next
-
Case 2580 ' catch the specific error
-
call FormFIX
-
Case Else ' All other errors will trap
-
Beep
-
MsgBox Err.Description
-
Exit Sub
-
End Select
-
Resume 0
-
-
End Sub
|  | Moderator | | Join Date: Nov 2006 Location: The Netherlands
Posts: 2,232
| | | re: Opening form after error
Hmm, why not test the table *before* opening the form?
Use e.g.: -
dim rs as DAO.recordset
-
set rs = currentdb.openrecordset("tblCen")
-
IF rs.eof and rs.bof then
-
' rebuild the table as nothing is there
-
endif
-
-
Docmd.openform "frmCen"
-
-
Nic;o)
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,875
| | | re: Opening form after error Quote:
Originally Posted by nico5038 Hmm, why not test the table *before* opening the form?
Use e.g.: -
dim rs as DAO.recordset
-
set rs = currentdb.openrecordset("tblCen")
-
IF rs.eof and rs.bof then
-
' rebuild the table as nothing is there
-
endif
-
-
Docmd.openform "frmCen"
-
-
Nic;o) Thanks Nico
Why didn't I think of that ... Doh!
|  | Expert | | Join Date: Jan 2007 Location: California
Posts: 3,835
| | | re: Opening form after error
What about an intermediary form? The original form builds the table and as the last thing it does, it opens the intermediary form. The intermediary form's On Load event closes the original form and then reopens it. The original form's On Load event closes the intermediary form.
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
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.
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Opening form after error
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
-
|  | Expert | | Join Date: Jan 2007 Location: California
Posts: 3,835
| | | re: Opening form after error
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.
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,875
| | | re: Opening form after error Quote:
Originally Posted by smiler2505 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?
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Opening form after error
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.
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
just tried the form open thing on its own, with form_onerror, with and without DoEvents...nothing
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.
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Opening form after error
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.
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,875
| | | re: Opening form after error Quote:
Originally Posted by smiler2505 just tried the form open thing on its own, with form_onerror, with and without DoEvents...nothing
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?
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Opening form after error
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 :)
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia
Posts: 5,214
| | | re: Opening form after error Quote:
Originally Posted by smiler2505 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_Table 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
-
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
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!
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error - Sub Form_Load()
-
On Error GoTo Notable
-
-
Notable:
-
Select Case Err
-
Case 0
-
Resume Next
-
Case 2580 ' catch the specific error
-
Call FormFIX
-
Case Else ' All other errors will trap
-
Beep
-
MsgBox Err.Description
-
Exit Sub
-
End Select
-
Resume 0
-
End Sub
Error still comes up, and the table is not built. FormFIX is a Sub (by default, Public) in another module called nonformsubs
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
Form open, form load etc do not work. The error of there being no record source for the form comes up first.
With the 'checking on database load'; is there anyway to loop it, so it always checks for the presence of the tables; if they don't exist, build them? Or to make a preliminary check before forms are opened?
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,722
| | | re: Opening form after error Quote:
Originally Posted by smiler2505 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'm afraid I haven't had a chance to go through the whole thread yet, but I had an idea which may help you. Apologies if this has been propounded already.
First, before I go on, have you tried creating the table then trying a .Requery? I'll assume you have considered that already.
Otherwise, think about creating another form, whose job it is simply to check for the existence of the table (and create it if/where necessary) then opens up your form and closes itself. You may even get away with having an invisible form to do the job if you prefer. I'm not sure that would work but you could try it if that appeals.
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
Tried it!
Basically, I can't open a form using DoCmd.OpenForm, because no form opens, and if I close the form then open it, using DoCmd.Close, access crashes, even if it is in a seperate sub, form, or module.
So, I think I'll just put an MsgBox at the end of the script and ask the user to reopen the form because an error has occured and has now been fixed.
That works at least! It doesn't solve the problem, but it'll do for an alternate solution at least. Unless anyone has any better ideas?
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,722
| | | re: Opening form after error Quote:
Originally Posted by smiler2505 Tried it!
Basically, I can't open a form using DoCmd.OpenForm, because no form opens, and if I close the form then open it, using DoCmd.Close, access crashes, even if it is in a seperate sub, form, or module.
So, I think I'll just put an MsgBox at the end of the script and ask the user to reopen the form because an error has occured and has now been fixed.
That works at least! It doesn't solve the problem, but it'll do for an alternate solution at least. Unless anyone has any better ideas? You leave us all guessing what exactly it was that you tried.
I find it hard to believe you've tried my suggestion and got those results, but if you can be a little clearer in what you're saying, I'm sure we can all understand.
|  | Expert | | Join Date: Jan 2007 Location: California
Posts: 3,835
| | | re: Opening form after error
Did you try compiling and setting a break to step through the code line by line yet?
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
I did the compiling thing, that's how I found out what was causing the crash.
On the form_error event, I included the code to build the table, and then put 'Me.Requery', 'Me.Repaint', and 'Me.Refresh', all to no effect; the table could not refresh when the form was opening.
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,722
| | | re: Opening form after error
Thank you. That's much clearer :)
Perhaps you'd like to give post #33 a try?
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
I have tried: 1. Building the table, and reopening the form after this has been done.
This built the table, but did not reopen the form. 2. Building the table, closing the form, and reopening it after.
This caused Access to crash, but if the form was closed after the table was built, the table existed. 3. Building the table, refreshing the form.
Table is built, but no form appears. 4. Building the table, and using 'DoEvents' before closing the form, and reopening it.
Access crashed, but built the table.
All of these were tried in various order, under various different form events.
Over the course of it I have learnt: 1. It is definetly the DoCmd.Close acForm, "frmCSN" that causes access to break. 2. Any action must start in the Form_OnError event.
Hope that helps clarify things. I'm sure inevitably there are things I have missed. I haven't as yet done the database (on load) idea.
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error Quote:
Originally Posted by NeoPa Thank you. That's much clearer :)
Perhaps you'd like to give post #33 a try? will do.
does anyone know if there is a timer function in vba?
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 10,875
| | | re: Opening form after error Quote:
Originally Posted by smiler2505 I have tried: 1. Building the table, and reopening the form after this has been done.
This built the table, but did not reopen the form. 2. Building the table, closing the form, and reopening it after.
This caused Access to crash, but if the form was closed after the table was built, the table existed. 3. Building the table, refreshing the form.
Table is built, but no form appears. 4. Building the table, and using 'DoEvents' before closing the form, and reopening it.
Access crashed, but built the table.
All of these were tried in various order, under various different form events.
Over the course of it I have learnt: 1. It is definetly the DoCmd.Close acForm, "frmCSN" that causes access to break. 2. Any action must start in the Form_OnError event.
Hope that helps clarify things. I'm sure inevitably there are things I have missed. I haven't as yet done the database (on load) idea. Have you tried Nicos suggestion of checking for the tables existance without opening the form at all and only opening the form after the table is found or built?
| | Member | | Join Date: Apr 2007
Posts: 72
| | | re: Opening form after error
I figured it out!
DoEvents wasn't working, but it had something to do with time; I had to wait for the error code to finish.
So... -
Sub Form_Error(DataErr As Integer, Response As Integer)
-
If DataErr = "2580" Then
-
-
Response = acDataErrContinue
-
DoCmd.OpenForm "FormFix"
-
-
End If
-
-
End Sub
-
-
Sub Form_Load()
-
Me.Visible = False
-
Me.TimerInterval = 2
-
-
End Sub
-
Sub Form_Timer()
-
DoCmd.SetWarnings False
-
-
On Error GoTo ExitCreateCwS
-
-
'Build table
-
-
ExitCreateCwS:
-
-
DoCmd.OpenForm "frmCSN"
-
DoCmd.Close acForm, Me.Name, acSaveNo
-
-
End Sub
-
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,722
| | | re: Opening form after error
Good for you.
It's great when it all comes together :)
|  | Similar Microsoft Access / VBA bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,419 network members.
|