This should not be so difficult right??

  • Thread starter Earl.AKA J.Alladien in access forum!!
  • Start date
E

Earl.AKA J.Alladien in access forum!!

Hello All,

I have the following code in my form "Begin" :

Private Sub Form_Timer()
CurrentDb.Execute "GO1", dbFailOnError
CurrentDb.Execute "GO3", dbFailOnError
CurrentDb.Execute "GO4", dbFailOnError
On Error Resume Next
End Sub

On Error I would like the DB to close my form "Begin" and open my other form
"Begin1"
How do I do that,I have tried but I am not very strong in code ...
Thanks in advance!
 
D

Dirk Goldgar

"Earl.AKA J.Alladien in access forum!!"
Hello All,

I have the following code in my form "Begin" :

Private Sub Form_Timer()
CurrentDb.Execute "GO1", dbFailOnError
CurrentDb.Execute "GO3", dbFailOnError
CurrentDb.Execute "GO4", dbFailOnError
On Error Resume Next
End Sub

On Error I would like the DB to close my form "Begin" and open my other
form
"Begin1"
How do I do that,I have tried but I am not very strong in code ...
Thanks in advance!


Do you want to close this form and open Begin1 after running all the
queries, even if there is no error? Here's a version that does it that way:

'----- start of code -----
Private Sub Form_Timer()

On Error GoTo Err_Handler

With CurrentDb
.Execute "GO1", dbFailOnError
.Execute "GO3", dbFailOnError
.Execute "GO4", dbFailOnError
End With

Finish_Up:
DoCmd.OpenForm "Begin1"
DoCmd.Close acForm, Me.Name, acSaveNo
Exit Sub

Err_Handler:
Resume Finish_Up

End Sub

'----- end of code -----

Alternatively, here's a version that closes this form and opens Begin1
*only* if there's an error:

'----- start of code -----
Private Sub Form_Timer()

On Error GoTo Err_Handler

With CurrentDb
.Execute "GO1", dbFailOnError
.Execute "GO3", dbFailOnError
.Execute "GO4", dbFailOnError
End With

Exit_Point:
Exit Sub

Err_Handler:
DoCmd.OpenForm "Begin1"
DoCmd.Close acForm, Me.Name, acSaveNo
Resume Exit_Point

End Sub

'----- end of code -----

In either case, do you really want to totally ignore whatever error
occurred? Some errors may be anticipated and acceptable, but others may
indicate a problem that the user ought to be told about. It seems to me
that it would be a good idea to check the error number (Err.Number) in the
error-handling code, and decide what to do based on that.

I note, also, that this code is running in the Timer event. If those
queries take a while to run, it's conceivable that the Timer event could
fire again while the event procedure is running. You may want to disable
the Timer event by setting Me.TimerInterval = 0 at the start of your event
procedure. If your circumstances warrant, you can turn the event back on
again before exiting the procedure.
 
E

Earl.AKA J.Alladien in access forum!!

Hi Dirk,

Thanks for your reply...
Hmm.. I think this could work let me just try it out and see if it does
what I want ,cause from what I see it should do the trick!
If not i'll get back to you ASAP!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top