-
WSmitchbvi
AskWoody LoungerJuly 18, 2015 at 4:55 pm in reply to: Losing values in publicly declared array in middle of sub #1515875Peter,
Another thing you might consider to to Explicitly Type each of your variables. As it is you are using Variants (the default data type) which are highly inefficient and chew up memory space. Also avoid multiple variables in one DIM give each its own line, takes up space but makes things easier to read. HTH :cheers:
I have tried the watch suggestion and I may not be doing it correctly , two watches first just the array name ArrTemp() and second a new line I added to check if the assignment to a cell was the problem
CheckEmpty = WorksheetFunction.StDev(ArrTestTemp())
Both showed in the watch window our of context and variant empty.
Added a little test to my code to check if the array was empty
Code:For Z = 1 To NoRecalcs If IsEmpty(ArrTemp(Z)) Then MsgBox “Array ” & Z & ” is empty ” End If Next Z ‘Do Calculations CheckEmpty = WorksheetFunction.StDev(ArrTestTemp()) MsgBox CheckEmpt
and it did not fail but the moment I tried to calculate the StDev of the Array I had just checked to have all the elements in place it is empty.
Thanks for the tip about defining the variants one of the reasons I added a Progress bar was to try and find where the procedure slowed down, writing to the worksheet certainly slows it. I assume that all but one of my arrays should be integer the odd one the names of the results a string or is there any other class that would speed things up.
Did not mention before but all of the routines in this procedure are in an Addin that I call from my personal workbook just in case it makes any difference.
Thank you again, I have been working on this routine for some time.
Take care
peter
-
WSmitchbvi
AskWoody LoungerJuly 18, 2015 at 1:19 pm in reply to: Losing values in publicly declared array in middle of sub #1515843Thanks for taking the time.
I do not get an error when running the Module at that point or any other, the ArrTemp() simply goes blank. Also as I pointed out in my post running a test with a worksheet that has cells that recalculate it works fine. Also as I said if I copy the results from the workbook with which I have the problem to another and then run the procedure on that work book I have copied the results to it works OK.
For completeness ArrTemp() splits the multiple ArrFinal( , ) into the number of outputs that have been selected. It changes each time the loop for outputs is run. It has been re dimensioned at the start of the sub routine I posted.
Sorry I cannot be more explicit and thanks again.
Peter
-
WSmitchbvi
AskWoody LoungerJuly 18, 2015 at 1:10 pm in reply to: Losing values in publicly declared array in middle of sub #1515842Peter,
Kind of hard to do this w/o the workbook in question but here are a couple of things you can check:
-
[*]You day the array is declared publicly…exactly how? If you are declaring it outside of any procedure with a Dim statement it is only visible in the same Module so if the Standard Deviation procedure is in another module it will be a different variable and have no data.
[*]Try using a Public statement vs Dim.
[*]Have you tried putting a Watch on the Array so the code breaks if the array gets wiped?
[*]Use this query {vba debugging watch expressions} in your browser to learn how to do watch expressions. Knowing the location of execution when the array goes blank can be a big help in finding the problem.HTH :cheers:
Thanks again, for taking the time. The array is Public and is in the same module as the code I posted. Just in case I have made an error this is the start of the module
Code:Option Explicit Option Base 1 Public NoRecalcs, NoBins, ArrXValues(), FrequencyArr, PctDone, PbarCheck, PBStart, PBEnd, ScaleMax, ScaleMin, ScaleMajor, _ ResultCells, ArrResultCells, NoOutPuts, ArrFinal, LabelCells, ArrLabelCells, NoLabels, BinFq, ColInc, Col1, Col2, i, y, x, Hi, n, _ ArrTemp(), ArrNDValues(), ArrBinHisto(), Response, PctDo, PctCheck, PrintData, WBtemp
I have not used watch expressions before so I will get to work on that.
The workbook in question is part of an estate plan so I would send it to you privately if acceptable but do not want to post it on line.
Thanks again
Peter
-
WSmitchbvi
AskWoody LoungerJuly 10, 2015 at 11:18 am in reply to: How to pass the result of a Frequency Function to an array #1514605Hi Zeddy
The Array is already defined as Public, I think it is something to do with the syntax. I tried to set the array to the two arrays that are the feed for the frequency function but that did not work. The only thing that does (so far) is actual setting the array to worksheet cells the same size as the input.
by the way since seeking help it has occurred to me that I need the data on the worksheet to build the chart other wise once I exit the routine the Chart will no longer have any input.
Thanks for taking the time to help.
Peter
-
WSmitchbvi
AskWoody LoungerRG
I think I have messed it up again I tried to reply using the email address you provided and was asked to authentic and that failed as well do you have my files yet?
Sorry
peter
-
WSmitchbvi
AskWoody LoungerHi Maud
Thanks for the input tried that and it does not cycle twice as it did on exit but it still goes to the command button “Next Stock” bypassing the next text box Opt 6 which is what I would have thought it would have gone to had the set focus command not worked. If the strike price is greater than the purchase price then it does just tab to the Opt6. It’s got me beat,I can live with it just not what is needed, it could be the strike is wrong as opposed to the purchase price however I wanted to start ta the first one and work back down the form.
Thanks again for your time
Peter
-
WSmitchbvi
AskWoody LoungerRG
Tried Application.enablevents= False/True same result
thanks
Peter
-
WSmitchbvi
AskWoody LoungerHi RG
Do not have a problem passing the file onto you. However I would like to do it directly as there are lots of bits of code from other people and I am not sure I have made that clear through the routines. As I was only going to use it myself it was not an issue but if it gets into the public domain I would like to make sure it is done properly. Can you let me know if I can send to you?
Have not tried your late suggestion will do and let you know thanks again for all your help.
Take care
peter
-
WSmitchbvi
AskWoody LoungerRG Thank you
Still no luck I changed your code to conform with my UserForm hopefully I did that correctly see below.
Private Sub Opt5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim iAns As Integer
If CDbl(Opt5.Value) 0 Then ‘Check to make sure Shares have been entered in multiples of 100
MsgBox “The number of shares must be in Units of 100”
Cancel = True
With Me.Opt4 ‘Selects the previous entry so it can be overwritten
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
End SubPrivate Sub Opt5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim iAns As Integer
If CDbl(Opt5.Value) < CDbl(Opt2.Value) Then
iAns = MsgBox("The Strike Prices is lower than the Purchase Price is this correct", _
vbYesNo, "Check Strike Price")
If iAns = vbNo Then
Me.Opt2.SetFocus
End If
End If
End SubPrivate Sub UserForm_Activate()
With EnterOptionData
.Top = Application.Top + 125
.Left = Application.Left + 600
End With
Opt1.SetFocus
End SubPrivate Sub UserForm_Initialize()
Opt1.SetFocus
Opt2.Text = Format(Number, "000.00")
Opt3.Text = Format(Number, "000.00")
Opt4.Text = Format(Number, "000.00")
Opt5.Text = Format(Number, "000.00")
End SubThank you and Take care
-
WSmitchbvi
AskWoody LoungerThanks for that suggestion, there is not a yes option unless I should include an else option in the if then but if the test is passed I want to move on. Deleting the cancel = true for some reason moves the focus to a command button not the next text box.
Take care
Peter
-
WSmitchbvi
AskWoody LoungerDecember 28, 2014 at 4:23 pm in reply to: Can you use an SQL statement as part of another in Having or Where conditions #1482252The start is a form that allows me to select a number of reports of which this sequence is one.
The Sub “ExpReport1Year” is called first that builds the two tables then it opens the report.
In this case it is the report for Expenses only. the field “Type” can be a revenue classification or it can be blank. If it is blank the batch is only for expenses. You can see the report is designed to be for a selected year.
Thanks again
Private Sub ExpOnly1PYear_Click()
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = “rptSelOpforExp”
Call ExpREport1Year
stLinkCriteria = “[OperatorID]=” & Me![OperatorID]
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
End SubPrivate Sub ExpREport1Year()
‘Creates a table of Batch numbers for the production year selected. 11192014
‘Remember the object is to get batch numbers that appear in the production year as it is possible that there may be items in prior years
Year1 = InputBox(“enter Production year”)DoCmd.SetWarnings False
‘Note TYpe is Null to make sure no revenue entrys are included
DoCmd.RunSQL “SELECT tblIncome_Expenditure.BatchID ” _
& “INTO tblBatchNoExpSelYear ” _
& “FROM tblIncome_Expenditure ” _
& “GROUP BY tblIncome_Expenditure.BatchID, ” _
& “tblIncome_Expenditure.Year, ” _
& “tblIncome_Expenditure.Type ” _
& “HAVING (((tblIncome_Expenditure.Year)=” & Year1 & “) ” _
& “AND ((tblIncome_Expenditure.Type) Is Null));”‘Creates a table of Data for the Selected year based on the Batch Numbersin the previous SQL statement
DoCmd.RunSQL “SELECT tblIncome_Expenditure.BatchID, ” _
& “tblIncome_Expenditure.OperatorID, ” _
& “tblIncome_Expenditure.Month, tblIncome_Expenditure.Year, ” _
& “Sum(tblIncome_Expenditure.Revenue) AS SumOfRevenue, ” _
& “Sum(tblIncome_Expenditure.Taxes) AS SumOfTaxes, ” _
& “Sum(tblIncome_Expenditure.GOthDedNothDeds) AS SumOfGOthDedNothDeds, ” _
& “Sum(tblIncome_Expenditure.Expenses) AS SumOfExpenses, ” _
& “Sum(tblIncome_Expenditure.NetThisEntry) AS SumOfNetThisEntry ” _
& “INTO tblExpOnlySelYear ” _
& “FROM tblBatchNoExpSelYear INNER JOIN tblIncome_Expenditure ” _
& “ON tblBatchNoExpSelYear.BatchID = tblIncome_Expenditure.BatchID ” _
& “GROUP BY tblIncome_Expenditure.BatchID, tblIncome_Expenditure.OperatorID, ” _
& “tblIncome_Expenditure.Month, tblIncome_Expenditure.Year ” _
& “HAVING (((tblIncome_Expenditure.Year)=” & Year1 – 1 & “)) ” _
& “OR (((tblIncome_Expenditure.Year)=” & Year1 & “)) ” _
& “OR (((tblIncome_Expenditure.Year)<[year]));"
DoCmd.SetWarnings True
End Sub -
WSmitchbvi
AskWoody LoungerDecember 28, 2014 at 12:19 pm in reply to: Can you use an SQL statement as part of another in Having or Where conditions #1482220Thank you both for taking the time to reply.
Mark, I will try and explain. The Batch # referred to in my earlier post groups records that may include both revenue and expenses. What I wanted to do was separate Batch’s that included revenue from those that did not. Hence by grouping on type ( the field I referred to as being null or not). This returned just the batch #’s for 1) revenue, 2)revenue and expenses or just 3)expenses. Using the batch numbers to return all of the records for the selected batch #’s produced the final result used to produce a report that was either Revenue or Expense based.
In the clumsy way I am presently doing this (hence the request for assistance) the first table which is just a list of batch numbers is joined to the main db to produce the second table which is the basis for the report.
Hope this makes sense thank you again.
Peter
-
WSmitchbvi
AskWoody LoungerDecember 2, 2014 at 10:51 am in reply to: Use Dmin (or other aggregate functions) on subset of records within query #1478125Thanks Mark , I am dense I know as I am still missing something but at least problem for now is solved and I will work on your suggestion.
-
WSmitchbvi
AskWoody LoungerDecember 1, 2014 at 11:17 am in reply to: Use Dmin (or other aggregate functions) on subset of records within query #1477955Hi Mark
first my apologies for not replying to your post but my internet has been down for two days.
Secondly I discovered that I need Max rather than Min, I had started out asking for Min thinking if i solved that Max would work.
I have managed to solve my problem but I had to use an aggregate function in a query. Once I had established what batches had to be processed I concatenated Year, Month (padded if one digit) and BatchID, used grouping to get the Max and then in the report sorted by the concatenated field then year and Month which put all the entries in the correct order.
My DB is not that large about 40K entries and in any year about 4 to 5K so I guess the efficiency is not that critical. However I would prefer to follow your advice but cannot work out how to do it.
This is the sql statement I get when I try and follow your suggestion.SELECT tblIncome_Expenditure.BatchID, tblIncome_Expenditure.Year, Max(tblRevOnlySelYear.Year)
AS MaxOfYear
FROM tblRevOnlySelYear INNER JOIN tblIncome_Expenditure
ON tblRevOnlySelYear.BatchID = tblIncome_Expenditure.BatchID
GROUP BY tblIncome_Expenditure.BatchID, tblIncome_Expenditure.Year;This does not give me the correct result.
Again my thanks for your time.
Peter
-
WSmitchbvi
AskWoody LoungerNovember 24, 2014 at 12:39 pm in reply to: Use Dmin (or other aggregate functions) on subset of records within query #1476773I had posted a reply and went to edit it and seem to loose the lot. First thank for taking the time to respond to my post unfortunately I feel I did not outline properly what the problem is.
The query is part of the routine to produce a report and what I want to do is have the report listed so it shows each month sequentially. The difficulty is that within each batch there are sometimes adjustments to prior months and years and infrequently there are two batches with the same last month.I have attached a PDF which shows data and the desired result, there is of course a other information but I thought this way kept it simple.
Thanks
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Are manuals extinct?
by
Susan Bradley
1 hour, 52 minutes ago -
Canonical ditching Sudo for Rust Sudo -rs starting with Ubuntu
by
Alex5723
5 hours, 2 minutes ago -
Network Issue
by
Casey H
11 hours, 33 minutes ago -
Fedora Linux is now an official WSL distro
by
Alex5723
17 hours, 1 minute ago -
May 2025 Office non-Security updates
by
PKCano
17 hours, 27 minutes ago -
Windows 10 filehistory including onedrive folder
by
Steve Bondy
19 hours, 23 minutes ago -
pages print on restart (Win 11 23H2)
by
cyraxote
18 hours, 38 minutes ago -
Windows 11 Insider Preview build 26200.5581 released to DEV
by
joep517
21 hours, 34 minutes ago -
Windows 11 Insider Preview build 26120.3950 (24H2) released to BETA
by
joep517
21 hours, 36 minutes ago -
Proton to drop prices after ruling against “Apple tax”
by
Cybertooth
1 day, 4 hours ago -
24H2 Installer – don’t see Option for non destructive install
by
JP
13 hours, 19 minutes ago -
Asking Again here (New User and Fast change only backups)
by
thymej
1 day, 16 hours ago -
How much I spent on the Mac mini
by
Will Fastie
15 hours, 43 minutes ago -
How to get rid of Copilot in Microsoft 365
by
Lance Whitney
10 hours, 54 minutes ago -
Spring cleanup — 2025
by
Deanna McElveen
1 day, 22 hours ago -
Setting up Windows 11
by
Susan Bradley
17 hours, 13 minutes ago -
VLC Introduces Cutting-Edge AI Subtitling and Translation Capabilities
by
Alex5723
1 day, 17 hours ago -
Powershell version?
by
CWBillow
1 day, 18 hours ago -
SendTom Toys
by
CWBillow
5 hours, 22 minutes ago -
Add shortcut to taskbar?
by
CWBillow
1 day, 22 hours ago -
Sycophancy in GPT-4o: What happened
by
Alex5723
2 days, 14 hours ago -
How can I install Skype on Windows 7?
by
Help
2 days, 13 hours ago -
Logitech MK850 Keyboard issues
by
Rush2112
1 day, 20 hours ago -
We live in a simulation
by
Alex5723
3 days, 4 hours ago -
Netplwiz not working
by
RetiredGeek
2 days, 15 hours ago -
Windows 11 24H2 is broadly available
by
Alex5723
3 days, 17 hours ago -
Microsoft is killing Authenticator
by
Alex5723
19 hours, 13 minutes ago -
Downloads folder location
by
CWBillow
3 days, 23 hours ago -
Remove a User from Login screen
by
CWBillow
2 days, 19 hours ago -
TikTok fined €530 million for sending European user data to China
by
Nibbled To Death By Ducks
3 days, 14 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.