Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Error message box

  Asked By: Kaua    Date: Mar 20    Category: MS Office    Views: 727
  

I am using the following code to update web qwery. Since the site
needs password so I use "Remenber me" in the site so that I do not
need to log in again. But the same expires after some days and I
need to relog in. Then the code executes an error. I want that
instead of showing the error msg, the code shall show following msg
"Please visit the web to re log in". Where this message is to put in
the code? Someone should please help!

I have modified the error handler message as shown below, but it is
showing the Message every time the code completes its task, ie
evenif there is no error

Code is given below:

Sub Update()
Application.ScreenUpdating = False
Application.DisplayStatusBar = True
Application.StatusBar = "Please wait while updating..."
Application.Wait Now + TimeValue("00:00:02")
On Error GoTo endo
Sheets("Web").Select
Range("A40").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("TOP").Select
Application.StatusBar = False

endo: MsgBox "Please relogin the web"
End Sub

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Eric Foster     Answered On: Mar 20

Try...

Sub Update()
Application.ScreenUpdating = False
Application.DisplayStatusBar = True
Application.StatusBar = "Please wait while updating..."
Application.Wait Now + TimeValue("00:00:02")
On Error GoTo endo
Sheets("Web").Select
Range("A40").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("TOP").Select
Application.StatusBar = False

Exit sub

endo: MsgBox "Please relogin the web"
End Sub

 
Answer #2    Answered By: Oliver Evans     Answered On: Mar 20

And don't forget to reset the error  catching before getting out of the
routine.

On Error GoTo 0
Exit Sub

Error handling is a touchy subject for a lot of people.

I tend to try and handle stuff "inline" as it were, and I use a variable to
catch the error number so that I can reset the handler immediately.

Public lgErrNum as long

Sub Update()

Application.ScreenUpdating = False
Application.DisplayStatusBar = True
Application.StatusBar = "Please wait while updating..."
Application.Wait Now + TimeValue("00:00:02")

On Error Resume next
Sheets("Web").Select
lgErrNum = Err.Number
On Error GoTo 0
Select case lgErrNum
Case 0
Case Else
Application.ScreenUpdating = True
Application.DisplayStatusBar = False
MsgBox "Please relogin the web"
Exit Sub
End Select

Range("A40").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("TOP").Select
Application.StatusBar = False

End Sub

Or....

On Error Resume next
Sheets("Web").Select
lgErrNum = Err.Number
On Error GoTo 0
Select case lgErrNum
Case 0
Range("A40").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("TOP").Select
case else
MsgBox "Please relogin the web"
End Select

Application.ScreenUpdating = True
Application.DisplayStatusBar = False



I's more coding I know but each error is dealt with there and then and it
becomes pretty standard. Also each error condition can be dealt with in the
select statement.

 
Answer #3    Answered By: Geb Chalthoum     Answered On: Mar 20

The message  box is the next line after Application.StatusBar = False, so
there is nothing to stop it being executed. Put in an Exit Sub after the
last line you want to execute.

 
Didn't find what you were looking for? Find more on Error message box Or get search suggestion and latest updates.




Tagged: