Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Blank Message Box after procedure execution

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Blank Message Box after procedure execution

Hi Toby,

Perhaps you could post an example of a problematic
procedure?


---
Regards,
Norman



wrote in message
oups.com...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Blank Message Box after procedure execution

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Blank Message Box after procedure execution

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


wrote in message
oups.com...
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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Blank Message Box after procedure execution

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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Blank Message Box after procedure execution

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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Blank Message Box after procedure execution

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

wrote in message
oups.com...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code Execution Message canderson Excel Discussion (Misc queries) 1 October 9th 09 04:28 PM
disable message box during VBA code execution juergenkemeter[_9_] Excel Programming 2 January 12th 06 01:16 AM
message without stopping execution? Stefi Excel Programming 19 July 14th 05 12:08 PM
Function/Procedure dependence & order of execution Jon L Excel Programming 1 October 3rd 04 10:06 AM
Message Box Execution Myrna Rodriguez Excel Programming 1 June 24th 04 06:34 PM


All times are GMT +1. The time now is 04:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"