Run one query, then another, then another... (1 Viewer)

ajetrumpet

Banned
Local time
Today, 02:24
Joined
Jun 22, 2007
Messages
5,638
this thread is getting lengthly mr. access. need some assistance? :D
 

vbaInet

AWF VIP
Local time
Today, 08:24
Joined
Jan 22, 2010
Messages
26,374
this thread is getting lengthly mr. access. need some assistance? :D
We're having a bit of a banter here Adam, so you're more than welcome to rejoin in the discussions and make some interesting contributions :D
 

ajetrumpet

Banned
Local time
Today, 02:24
Joined
Jun 22, 2007
Messages
5,638
We're having a bit of a banter here Adam, so you're more than welcome to rejoin in the discussions and make some interesting contributions :D

i am a boring guy and I offer nothing interesting. so go ahead and fight to the death on it....good luck!
 

vbaInet

AWF VIP
Local time
Today, 08:24
Joined
Jan 22, 2010
Messages
26,374
i'm sure most would disagree. the OP would be would delighted to hear more ideas.
 

vbaInet

AWF VIP
Local time
Today, 08:24
Joined
Jan 22, 2010
Messages
26,374
Just out of curiousity and for the benefit of readers that may stumble upon this thread, what approach did you eventually take?
 

jomuir

Registered User.
Local time
Today, 08:24
Joined
Feb 13, 2007
Messages
154
I went with this solution, as it shows an hour glass and also provides a description of what is happening....

Private Sub RunAllQueries___Click()

DoCmd.Hourglass True

Dim myQueries() As String, i As Integer, myDb As Database
Set myDb = CurrentDb
ReDim myQueries(3)
myQueries(0) = "0 - Clear Out yealry accamend - required tbl"
myQueries(1) = "0 - Clear Out yearly acc amend tbl"
myQueries(2) = "0 Clear out ALL DATA table"
myQueries(3) = "0 Clear out Merged_Stock Table"

For i = 0 To UBound(myQueries)
DoCmd.Echo True, "Running query " & i + 1 & " of 4 please wait...."
myDb.Execute myQueries(i)
Next

DoCmd.Hourglass False
End Sub
 

vbaInet

AWF VIP
Local time
Today, 08:24
Joined
Jan 22, 2010
Messages
26,374
Looks good :) One thing though, remember your error handling code.

Thanks for posting back with your success.
 

jomuir

Registered User.
Local time
Today, 08:24
Joined
Feb 13, 2007
Messages
154
Very bad....but I never have put in error handling, but just read up on it and it make sense to have!! However, after thinking it would be easy to add this fails "Label not defined" and highlights the second line.....any ideas?

Private Sub RunAllQueries___Click()
On Error GoTo Err_RunAllQueries
DoCmd.Hourglass True

Dim myQueries() As String, i As Integer, myDb As Database
Set myDb = CurrentDb
ReDim myQueries(3)
myQueries(0) = "0 - Clear Out yealry accamend - required tbl"
myQueries(1) = "0 - Clear Out yearly acc amend tbl"
myQueries(2) = "0 Clear out ALL DATA table"
myQueries(3) = "0 Clear out Merged_Stock Table"

For i = 0 To UBound(myQueries)
DoCmd.Echo True, "Running query " & i + 1 & " of 4 please wait...."
myDb.Execute myQueries(i)
Next

DoCmd.Hourglass False
Exit_RunAllQueries:
End Sub
Err_RunAllQueries:
MsgBox Err.Description
Resume Exit_RunAllQueries
End Sub
 

vbaInet

AWF VIP
Local time
Today, 08:24
Joined
Jan 22, 2010
Messages
26,374
DoCmd.Hourglass False
Exit_RunAllQueries:
End Sub

Change that to Exit Sub. You end a routine/function, but exit if you want to "break" out of it.
 

vbaInet

AWF VIP
Local time
Today, 08:24
Joined
Jan 22, 2010
Messages
26,374
Code:
Err_RunAllQueries:
    MsgBox Err.Description
[COLOR=Blue]DoCmd.Hourglass False[/COLOR]
    Resume Exit_RunAllQueries
End Sub

The blue was the main reason I reminded you of error handling. include that too.
 

vbaInet

AWF VIP
Local time
Today, 08:24
Joined
Jan 22, 2010
Messages
26,374
No worries. Actually put that before the message box.

Have fun with the rest of your db.:)
 

Users who are viewing this thread

Top Bottom