Jim You can't debug if you leave that error trap in place. Comment out the line:
On Error GoTo Error_ErrorHandler
Then open the form again. If an error occurs your code will break instead of ignoring the error. And for a better error trap put something useful in it so you know what happened. My error traps typically look like this:
Public Sub TestCode()
On Error GoTo err_PROC
'Do Something here
exit_PROC:
On Error Resume Next
Exit Sub
err_PROC:
Dim strErrMsg As String
Dim lngIcon As Long
strErrMsg = "Error " & Err.Number & " (" & Err.Description & ") " _
& "occurred in procedure TestCode of " _
& "VBA Document basUtil_AppMasterSystem"
lngIcon = vbOKOnly + vbInformation
MsgBox strErrMsg, lngIcon, "Error"
Resume exit_PROC
End Sub
Bill
---In MS_Access_Professionals@yahoogroups.com, <luvmymelody@yahoo.com> wrote:
So here is my code and it is not deleting the records and appending the records. I deleted 100 records and it is still the same. I added some msgbox's to see how it is working.
Private Sub Form_Load()
' Enable error handler.
On Error GoTo Error_ErrorHandler
Dim db As DAO.Database
Set db = CurrentDb
db.Execute "qryDeleteAllFromSupervisorTable", dbFailOnError
MsgBox "Hi"
db.Execute "qryAppendSupervisorTable", dbFailOnError
MsgBox "Hi"
Exit_ErrorHandler:
Exit Sub
Error_ErrorHandler:
Resume Exit_ErrorHandler
End Sub
Jim Wagner
On Wednesday, February 5, 2014 9:06 AM, Glenn Lloyd <argeedblu@gmail.com> wrote:
Jim,
If you use the code John suggested, you also will not need to fiddle with SetWarnings. You can delete both of those DoCmd statements.
Glenn
From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of John Viescas
Sent: Wednesday, February 5, 2014 11:00 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] AutoExec or something else?
Jim-
Don't use OpenQuery. Use:
db.Execute "first query", dbFailOnError
db.Execute "second query", dbFailOnError
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications
SQL Queries for Mere Mortals
I put the code in the On Open event and only the first query ran. The second query did not run. If I put the code behind a button on the form, both queries run. I added msgbox's to see if it gets past the 1st and second queries but the second msgbox never appears. Below is my code.
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Error_ErrorHandler
DoCmd.OpenQuery "qryDeleteAllFromSupervisorTable" 'Deletes all records in the supervisortable
DoCmd.OpenQuery "qryAppendSupervisorTable" 'Appends all records from the tblSourcetblSupervisorList table
On Wednesday, February 5, 2014 8:41 AM, John Viescas <JohnV@msn.com> wrote:
AutoExec macro or put code to run the queries in the Load event of the form that you open at startup.
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications
SQL Queries for Mere Mortals
How do I have 2 queries run each time the database is opened. Do I have to use an AutoExec macro or is there another way of programming it?
Tidak ada komentar:
Posting Komentar