PC Review


Reply
Thread Tools Rate Thread

Blank Message Box after procedure execution

 
 
sybot_uk@yahoo.co.uk
Guest
Posts: n/a
 
      31st May 2007
Aplogies if this is a bit basic but does anyone now how to get rid of
the blank message box with just and OK button which appears after each
sub procedure I run? I'm using excel 2003 vba, the message box appears
after each procedure whether I call the macro from the macro menu or
using a call statment from within another procedure.

I have tried searching for the answer but to no avail. Hope somone can
help

Toby

 
Reply With Quote
 
 
 
 
Norman Jones
Guest
Posts: n/a
 
      31st May 2007
Hi Toby,

Perhaps you could post an example of a problematic
procedure?


---
Regards,
Norman



<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Aplogies if this is a bit basic but does anyone now how to get rid of
> the blank message box with just and OK button which appears after each
> sub procedure I run? I'm using excel 2003 vba, the message box appears
> after each procedure whether I call the macro from the macro menu or
> using a call statment from within another procedure.
>
> I have tried searching for the answer but to no avail. Hope somone can
> help
>
> Toby
>



 
Reply With Quote
 
sybot_uk@yahoo.co.uk
Guest
Posts: n/a
 
      1st Jun 2007
Here is an example:


Public mth As Integer, yr As Integer, strDisplayMonth As String,
strDisplayFiscYrStart As String, strDisplayYrStart As String

Sub Get_Params()

On Error GoTo Get_Params_err

'If there is no value in the combo box raise a message otherwise set
the month variable to the value
If frmParameters.Controls("cboMth").Value = "" Or
frmParameters.Controls("cboMth").Value < 1 Or
frmParameters.Controls("cboMth").Value > 12 Then
MsgBox ("Please enter a valid month")
End
Else: mth = frmParameters.Controls("cboMth").Value
End If


'If there is no value in the combo box raise a message otherwise set
the year variable to the value
If frmParameters.Controls("cboYr").Value = "" Or
frmParameters.Controls("cboYr").Value < 2000 Or
frmParameters.Controls("cboYr").Value > 2020 Then
MsgBox ("Please enter a valid year")
End
Else: yr = frmParameters.Controls("cboYr").Value
End If

''''''''''''''Get the values for display''''''''''''''''''''''''
'get month name and year for display
strDisplayMonth = MonthName(mth)
strDisplayMonth = strDisplayMonth & " " & yr
Worksheets("Display").Range("B1").Value = strDisplayMonth
'get year start for display
strDisplayFiscYrStart = "April"
If mth > 3 Then
strDisplayFiscYrStart = strDisplayFiscYrStart & " " & yr
ElseIf mth < 4 Then
strDisplayFiscYrStart = strDisplayFiscYrStart & " " & (yr - 1)
End If
Worksheets("Display").Range("B2").Value = strDisplayFiscYrStart
'Get year start for display
If mth < 12 Then
strDisplayYrStart = MonthName(mth + 1) & " " & yr - 1
ElseIf mth = 12 Then
strDisplayYrStart = MonthName(1) & " " & yr
End If
Worksheets("Display").Range("B3").Value = strDisplayYrStart
'get year for display
Worksheets("Display").Range("B4").Value = yr


Get_Params_err:
MsgBox Error$
Exit Sub

End Sub

The workbook pulls data down from SQL Server by executing stored
proecedures. This sub sorts out the parameters being passed to the
procedure and saves them in public variables for use by the other
procedures.

Thanks in advance,

Toby


 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      1st Jun 2007
Hi Toby

Try replacing:

> Get_Params_err:
> MsgBox Error$
> Exit Sub
>
> End Sub



with

Exit Sub
Get_Params_err:
MsgBox Error$
Exit Sub

End Sub

In your code the MsgBox gets called even if there is
no error.


---
Regards,
Norman


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Here is an example:
>
>
> Public mth As Integer, yr As Integer, strDisplayMonth As String,
> strDisplayFiscYrStart As String, strDisplayYrStart As String
>
> Sub Get_Params()
>
> On Error GoTo Get_Params_err
>
> 'If there is no value in the combo box raise a message otherwise set
> the month variable to the value
> If frmParameters.Controls("cboMth").Value = "" Or
> frmParameters.Controls("cboMth").Value < 1 Or
> frmParameters.Controls("cboMth").Value > 12 Then
> MsgBox ("Please enter a valid month")
> End
> Else: mth = frmParameters.Controls("cboMth").Value
> End If
>
>
> 'If there is no value in the combo box raise a message otherwise set
> the year variable to the value
> If frmParameters.Controls("cboYr").Value = "" Or
> frmParameters.Controls("cboYr").Value < 2000 Or
> frmParameters.Controls("cboYr").Value > 2020 Then
> MsgBox ("Please enter a valid year")
> End
> Else: yr = frmParameters.Controls("cboYr").Value
> End If
>
> ''''''''''''''Get the values for display''''''''''''''''''''''''
> 'get month name and year for display
> strDisplayMonth = MonthName(mth)
> strDisplayMonth = strDisplayMonth & " " & yr
> Worksheets("Display").Range("B1").Value = strDisplayMonth
> 'get year start for display
> strDisplayFiscYrStart = "April"
> If mth > 3 Then
> strDisplayFiscYrStart = strDisplayFiscYrStart & " " & yr
> ElseIf mth < 4 Then
> strDisplayFiscYrStart = strDisplayFiscYrStart & " " & (yr - 1)
> End If
> Worksheets("Display").Range("B2").Value = strDisplayFiscYrStart
> 'Get year start for display
> If mth < 12 Then
> strDisplayYrStart = MonthName(mth + 1) & " " & yr - 1
> ElseIf mth = 12 Then
> strDisplayYrStart = MonthName(1) & " " & yr
> End If
> Worksheets("Display").Range("B3").Value = strDisplayYrStart
> 'get year for display
> Worksheets("Display").Range("B4").Value = yr
>
>
> Get_Params_err:
> MsgBox Error$
> Exit Sub
>
> End Sub
>
> The workbook pulls data down from SQL Server by executing stored
> proecedures. This sub sorts out the parameters being passed to the
> procedure and saves them in public variables for use by the other
> procedures.
>
> Thanks in advance,
>
> Toby
>
>



 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      1st Jun 2007
Hi Toby,

> Exit Sub
> Get_Params_err:
> MsgBox Error$
> Exit Sub


My suggested replacement should have read:


Exit Sub
Get_Params_err:
MsgBox Error$


---
Regards,
Norman


 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      1st Jun 2007
look like you need to read up on Error Handling. here's the MS take:
http://support.microsoft.com/kb/146864

Hint: Exit before your error handler label.

Also, there is very seldom any reason to use "End" in your code. Read the
Help for its effect.
It would seem you need "Exit Sub" here.

Also, from a design point of view, why do you need this code ?
> If frmParameters.Controls("cboMth").Value = "" Or
> frmParameters.Controls("cboMth").Value < 1 Or
> frmParameters.Controls("cboMth").Value > 12 Then
> MsgBox ("Please enter a valid month")


Assuming this is you code, fill cboMth with only 1-12. Possibly default to a
select value. may this month.

NickHK

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Here is an example:
>
>
> Public mth As Integer, yr As Integer, strDisplayMonth As String,
> strDisplayFiscYrStart As String, strDisplayYrStart As String
>
> Sub Get_Params()
>
> On Error GoTo Get_Params_err
>
> 'If there is no value in the combo box raise a message otherwise set
> the month variable to the value
> If frmParameters.Controls("cboMth").Value = "" Or
> frmParameters.Controls("cboMth").Value < 1 Or
> frmParameters.Controls("cboMth").Value > 12 Then
> MsgBox ("Please enter a valid month")
> End
> Else: mth = frmParameters.Controls("cboMth").Value
> End If
>
>
> 'If there is no value in the combo box raise a message otherwise set
> the year variable to the value
> If frmParameters.Controls("cboYr").Value = "" Or
> frmParameters.Controls("cboYr").Value < 2000 Or
> frmParameters.Controls("cboYr").Value > 2020 Then
> MsgBox ("Please enter a valid year")
> End
> Else: yr = frmParameters.Controls("cboYr").Value
> End If
>
> ''''''''''''''Get the values for display''''''''''''''''''''''''
> 'get month name and year for display
> strDisplayMonth = MonthName(mth)
> strDisplayMonth = strDisplayMonth & " " & yr
> Worksheets("Display").Range("B1").Value = strDisplayMonth
> 'get year start for display
> strDisplayFiscYrStart = "April"
> If mth > 3 Then
> strDisplayFiscYrStart = strDisplayFiscYrStart & " " & yr
> ElseIf mth < 4 Then
> strDisplayFiscYrStart = strDisplayFiscYrStart & " " & (yr - 1)
> End If
> Worksheets("Display").Range("B2").Value = strDisplayFiscYrStart
> 'Get year start for display
> If mth < 12 Then
> strDisplayYrStart = MonthName(mth + 1) & " " & yr - 1
> ElseIf mth = 12 Then
> strDisplayYrStart = MonthName(1) & " " & yr
> End If
> Worksheets("Display").Range("B3").Value = strDisplayYrStart
> 'get year for display
> Worksheets("Display").Range("B4").Value = yr
>
>
> Get_Params_err:
> MsgBox Error$
> Exit Sub
>
> End Sub
>
> The workbook pulls data down from SQL Server by executing stored
> proecedures. This sub sorts out the parameters being passed to the
> procedure and saves them in public variables for use by the other
> procedures.
>
> Thanks in advance,
>
> Toby
>
>



 
Reply With Quote
 
sybot_uk@yahoo.co.uk
Guest
Posts: n/a
 
      1st Jun 2007
Thankyou both very much for your help.
Norman, I will try what you have suggested.
Nick, I have used end because this sub is called from another
procedure (in fact by several procedures, I seperated it out so I
could re-use it), if the values are incorrect I don't want the calling
procedure to carry on running. I thought this would be OK, perhaps I'm
missing something fundamental, I'll definately read the link you
posted.

Thanks again,

Toby

 
Reply With Quote
 
sybot_uk@yahoo.co.uk
Guest
Posts: n/a
 
      1st Jun 2007
It's now working, I have changed my error handling. I also set the
MatchRequired property of the combo boxes to true so i could remove
the code I was using to check the values were valid.

Many Thanks,

Toby


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controlling execution of a Sub Procedure -Part 2 :( Don McC Microsoft Excel Programming 0 20th Apr 2010 03:27 PM
Controlling execution of a Sub Procedure Don McC Microsoft Excel Programming 1 19th Apr 2010 10:27 PM
why does the execution jump to another procedure? Harold Good Microsoft Excel Programming 4 14th May 2009 02:21 PM
too much for stored procedure execution Keith O Microsoft ADO .NET 3 15th Feb 2005 07:19 PM
Scheduling Procedure execution Sonali Microsoft VB .NET 1 1st Dec 2003 08:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:42 AM.