PC Review


Reply
Thread Tools Rate Thread

Calling Subroutines from sub-routine

 
 
Jeff
Guest
Posts: n/a
 
      26th Oct 2009
I have 2 subroutines in my EXCEL 2003 workbook and they are each assigned to
the CLICK event of their own button.

The first subroutine performs a pass-thru extraction from a SQL database.
There is a SUMMARY sheet in the workbook that then does some calculations on
the data that is extracted using the DCount and DCountA functions into
specific cells on the SUMMARY sheet.

The second sub-routine copies the resultant values calculated using the
DCount and DCountA functions onto another workbook that I'm going to use to
generate a trend chart.

If I click the first button and then the second button, every thing works as
I'd expect. What I want to do is call the second sub-routine as the last
line in the first sub-routine. When I do this the first sub-routine works
the same but the second sub-routine puts zeroes instead of the values from
the SUMMARY sheet.

Help...


 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      26th Oct 2009
Post the before and after code, what works run independently, and how you
merged them.

--
__________________________________
HTH

Bob

"Jeff" <(E-Mail Removed)> wrote in message
news:312BE3CE-178E-4E7E-82DB-(E-Mail Removed)...
>I have 2 subroutines in my EXCEL 2003 workbook and they are each assigned
>to
> the CLICK event of their own button.
>
> The first subroutine performs a pass-thru extraction from a SQL database.
> There is a SUMMARY sheet in the workbook that then does some calculations
> on
> the data that is extracted using the DCount and DCountA functions into
> specific cells on the SUMMARY sheet.
>
> The second sub-routine copies the resultant values calculated using the
> DCount and DCountA functions onto another workbook that I'm going to use
> to
> generate a trend chart.
>
> If I click the first button and then the second button, every thing works
> as
> I'd expect. What I want to do is call the second sub-routine as the last
> line in the first sub-routine. When I do this the first sub-routine works
> the same but the second sub-routine puts zeroes instead of the values from
> the SUMMARY sheet.
>
> Help...
>
>



 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      27th Oct 2009
It works when I run them independently but not this way.

Sub Get_Data()

Worksheets("PlaterMetricsData").Range("A1").Select
With ActiveSheet.QueryTables.Add(insert args here)
.CommandText = "EXEC ...."
.Name = "PlaterData"
.Refresh
End With

Populate_CurrentDataTable

Worksheets("Summary").Select

End Sub

Sub Populate_CurrentDataTable()
Dim dteDate As Date, iShift3Bars As Integer, iShift3Cycles As Integer

dteDate = Worksheets("Summary").Range("C1").Value
Worksheets("Summary").Select
iShift3Bars = Worksheets("Summary").Range("M5").Value
iShift3Cycles = Worksheets("Summary").Range("M6").Value

If Worksheets("Summary").Range("F1").Value = 1 Then
Worksheets("CycleInfoSQL").Select
ActiveSheet.Range("A3").Select
Do While IsEmpty(ActiveCell) = False
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = dteDate
ActiveCell.Offset(0, 1).Value = iShift3Bars
ActiveCell.Offset(0, 2).Value = iShift3Cycles

End If

Worksheets("Summary").Select

End Sub

"Bob Phillips" wrote:

> Post the before and after code, what works run independently, and how you
> merged them.
>
> --
> __________________________________
> HTH
>
> Bob
>
> "Jeff" <(E-Mail Removed)> wrote in message
> news:312BE3CE-178E-4E7E-82DB-(E-Mail Removed)...
> >I have 2 subroutines in my EXCEL 2003 workbook and they are each assigned
> >to
> > the CLICK event of their own button.
> >
> > The first subroutine performs a pass-thru extraction from a SQL database.
> > There is a SUMMARY sheet in the workbook that then does some calculations
> > on
> > the data that is extracted using the DCount and DCountA functions into
> > specific cells on the SUMMARY sheet.
> >
> > The second sub-routine copies the resultant values calculated using the
> > DCount and DCountA functions onto another workbook that I'm going to use
> > to
> > generate a trend chart.
> >
> > If I click the first button and then the second button, every thing works
> > as
> > I'd expect. What I want to do is call the second sub-routine as the last
> > line in the first sub-routine. When I do this the first sub-routine works
> > the same but the second sub-routine puts zeroes instead of the values from
> > the SUMMARY sheet.
> >
> > Help...
> >
> >

>
>
> .
>

 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      27th Oct 2009
step into Get_Data
set the next step at the line Populate_CurrentDataTable then step (F8) ...is
there an error message?
Are these two procedures in a standard module? If they're on a sheet code
page, are they on the same page?


"Jeff" wrote:

> It works when I run them independently but not this way.
>
> Sub Get_Data()
>
> Worksheets("PlaterMetricsData").Range("A1").Select
> With ActiveSheet.QueryTables.Add(insert args here)
> .CommandText = "EXEC ...."
> .Name = "PlaterData"
> .Refresh
> End With
>
> Populate_CurrentDataTable
>
> Worksheets("Summary").Select
>
> End Sub
>
> Sub Populate_CurrentDataTable()
> Dim dteDate As Date, iShift3Bars As Integer, iShift3Cycles As Integer
>
> dteDate = Worksheets("Summary").Range("C1").Value
> Worksheets("Summary").Select
> iShift3Bars = Worksheets("Summary").Range("M5").Value
> iShift3Cycles = Worksheets("Summary").Range("M6").Value
>
> If Worksheets("Summary").Range("F1").Value = 1 Then
> Worksheets("CycleInfoSQL").Select
> ActiveSheet.Range("A3").Select
> Do While IsEmpty(ActiveCell) = False
> ActiveCell.Offset(1, 0).Select
> Loop
> ActiveCell.Value = dteDate
> ActiveCell.Offset(0, 1).Value = iShift3Bars
> ActiveCell.Offset(0, 2).Value = iShift3Cycles
>
> End If
>
> Worksheets("Summary").Select
>
> End Sub
>
> "Bob Phillips" wrote:
>
> > Post the before and after code, what works run independently, and how you
> > merged them.
> >
> > --
> > __________________________________
> > HTH
> >
> > Bob
> >
> > "Jeff" <(E-Mail Removed)> wrote in message
> > news:312BE3CE-178E-4E7E-82DB-(E-Mail Removed)...
> > >I have 2 subroutines in my EXCEL 2003 workbook and they are each assigned
> > >to
> > > the CLICK event of their own button.
> > >
> > > The first subroutine performs a pass-thru extraction from a SQL database.
> > > There is a SUMMARY sheet in the workbook that then does some calculations
> > > on
> > > the data that is extracted using the DCount and DCountA functions into
> > > specific cells on the SUMMARY sheet.
> > >
> > > The second sub-routine copies the resultant values calculated using the
> > > DCount and DCountA functions onto another workbook that I'm going to use
> > > to
> > > generate a trend chart.
> > >
> > > If I click the first button and then the second button, every thing works
> > > as
> > > I'd expect. What I want to do is call the second sub-routine as the last
> > > line in the first sub-routine. When I do this the first sub-routine works
> > > the same but the second sub-routine puts zeroes instead of the values from
> > > the SUMMARY sheet.
> > >
> > > Help...
> > >
> > >

> >
> >
> > .
> >

 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      27th Oct 2009
When I put a Breakpoint in the code and then run it; subsequently, stepping
(F8) through the code - including following the call statement into the next
routine, everything works fine.

When I remove the breakpoint and let it run un-interrupted...it puts zeroes
in all the fields.

It's almost like the source data isn't getting updated or something and when
I manually cause the code to stop, it works.


"Patrick Molloy" wrote:

> step into Get_Data
> set the next step at the line Populate_CurrentDataTable then step (F8) ...is
> there an error message?
> Are these two procedures in a standard module? If they're on a sheet code
> page, are they on the same page?
>
>
> "Jeff" wrote:
>
> > It works when I run them independently but not this way.
> >
> > Sub Get_Data()
> >
> > Worksheets("PlaterMetricsData").Range("A1").Select
> > With ActiveSheet.QueryTables.Add(insert args here)
> > .CommandText = "EXEC ...."
> > .Name = "PlaterData"
> > .Refresh
> > End With
> >
> > Populate_CurrentDataTable
> >
> > Worksheets("Summary").Select
> >
> > End Sub
> >
> > Sub Populate_CurrentDataTable()
> > Dim dteDate As Date, iShift3Bars As Integer, iShift3Cycles As Integer
> >
> > dteDate = Worksheets("Summary").Range("C1").Value
> > Worksheets("Summary").Select
> > iShift3Bars = Worksheets("Summary").Range("M5").Value
> > iShift3Cycles = Worksheets("Summary").Range("M6").Value
> >
> > If Worksheets("Summary").Range("F1").Value = 1 Then
> > Worksheets("CycleInfoSQL").Select
> > ActiveSheet.Range("A3").Select
> > Do While IsEmpty(ActiveCell) = False
> > ActiveCell.Offset(1, 0).Select
> > Loop
> > ActiveCell.Value = dteDate
> > ActiveCell.Offset(0, 1).Value = iShift3Bars
> > ActiveCell.Offset(0, 2).Value = iShift3Cycles
> >
> > End If
> >
> > Worksheets("Summary").Select
> >
> > End Sub
> >
> > "Bob Phillips" wrote:
> >
> > > Post the before and after code, what works run independently, and how you
> > > merged them.
> > >
> > > --
> > > __________________________________
> > > HTH
> > >
> > > Bob
> > >
> > > "Jeff" <(E-Mail Removed)> wrote in message
> > > news:312BE3CE-178E-4E7E-82DB-(E-Mail Removed)...
> > > >I have 2 subroutines in my EXCEL 2003 workbook and they are each assigned
> > > >to
> > > > the CLICK event of their own button.
> > > >
> > > > The first subroutine performs a pass-thru extraction from a SQL database.
> > > > There is a SUMMARY sheet in the workbook that then does some calculations
> > > > on
> > > > the data that is extracted using the DCount and DCountA functions into
> > > > specific cells on the SUMMARY sheet.
> > > >
> > > > The second sub-routine copies the resultant values calculated using the
> > > > DCount and DCountA functions onto another workbook that I'm going to use
> > > > to
> > > > generate a trend chart.
> > > >
> > > > If I click the first button and then the second button, every thing works
> > > > as
> > > > I'd expect. What I want to do is call the second sub-routine as the last
> > > > line in the first sub-routine. When I do this the first sub-routine works
> > > > the same but the second sub-routine puts zeroes instead of the values from
> > > > the SUMMARY sheet.
> > > >
> > > > Help...
> > > >
> > > >
> > >
> > >
> > > .
> > >

 
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
Calling Subrountines within subroutines Tangier Microsoft Excel Discussion 4 30th Sep 2008 01:17 AM
Calling subroutines in subforms Funkykase@gmail.com Microsoft Access Form Coding 0 27th Feb 2008 11:16 PM
Calling subroutines from Class Modules davidm Microsoft Excel Programming 1 23rd Feb 2006 03:42 AM
Temporary tables and calling subroutines Mark Microsoft Access Form Coding 3 16th Mar 2004 07:40 AM
Calling Add-In subroutines from other modules =?Utf-8?B?c2NsYXJr?= Microsoft Excel Programming 5 3rd Feb 2004 05:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:40 PM.