-
This is probably a super lame question, but I have no idea how to access the form object of a form that I have created in my VBA project.
Using the Microsoft Visual Basic editor I added a form called "ChartGenerator". I outfitted it with buttons and drop downs; all of which I renamed so that within the form code I could access the choosen values.
My problem comes when I try to Load the form within my code.
I swore all I needed to do was:
Load ChartGenerator
ChartGenerator.Show
But I am getting a debugging error on the Load... any ideas why? I assume just trying to load an unidentified variable like ChartGenerator is the problem, but I dont know how to do this. I looked on MSDN online and came up with ziltch. I think I have to Open it before I load it, but I still am missing a step.
----------------------------------------------------------------
Here is the code to get attempt to Load the Form:
Sub GenerateUserCreatedChart()
Load ChartGenerator
ChartGenerator.Show
End Sub
----------------------------------------------------------------
Here is the code within the From itself:
Private Sub UserForm_Activate()
End Sub
Private Sub CreateChart_Click()
' Send out selections and close
Dim arrayPosition As Integer
Dim chartTitle As String
Dim fieldOne As String
Dim fieldTwo As String
Dim fieldThree As String
Dim fieldFour As String
Dim fieldFive As String
Dim userArray(10) As pivotType
arrayPosition = 0
Do While (arrayPosition <= 10)
userArray(arrayPosition).entryOne.name = getFieldOne
userArray(arrayPosition).entryTwo.name = getFieldTwo
userArray(arrayPosition).entryThree.name = getFieldThree
userArray(arrayPosition).entryFour.name = getFieldFour
userArray(arrayPosition).entryFive.name = getFieldFive
userArray(arrayPosition).isEmpty = True
arrayPosition = arrayPosition + 1
Loop
Module1.CreateChartAndTable userArray, getChartTitle, getWhetherToSumFieldTwo
Unload ChartGenerator
End Sub
Sub Fill_ListBoxes()
Dim columnLetter As Integer
Dim rangeInt As Integer
rangeInt = 8 ' start location
Dim stringTest As String
rangeLettersArray = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC", "AD", "AE", "AF", "AG")
columnLetter = 0
Do While Not isEmpty(Worksheets("Sheet5").Range(rangeLettersArray(columnLetter) & "7"))
' Always test for nulls
If (rangeLettersArray(columnLetter) = "G" Or rangeLettersArray(columnLetter) = "H" Or _
rangeLettersArray(columnLetter) = "I" Or rangeLettersArray(columnLetter) = "J") Then ' numeric
NumericList.AddItem Worksheets("Sheet5").Range(rangeLettersArray(columnLetter) & "7").value
Else
InfoBox1.AddItem Worksheets("Sheet5").Range(rangeLettersArray(columnLetter) & "7").value
InfoBox2.AddItem Worksheets("Sheet5").Range(rangeLettersArray(columnLetter) & "7").value
InfoBox3.AddItem Worksheets("Sheet5").Range(rangeLettersArray(columnLetter) & "7").value
InfoBox4.AddItem Worksheets("Sheet5").Range(rangeLettersArray(columnLetter) & "7").value
End If
' If Not IsNull(rst!UomID) Then cbo.ItemData(cbo.NewIndex) = rst!UomID
columnLetter = columnLetter + 1
Loop
InfoBox1.AddItem "dateTime"
InfoBox2.AddItem "dateTime"
InfoBox3.AddItem "dateTime"
InfoBox4.AddItem "dateTime"
End Sub
Private Sub UserForm_Initialize()
Fill_ListBoxes
End Sub
Function getFieldOne() As String
getFieldOne = NumericList.value
End Function
Function getFieldTwo() As String
getFieldTwo = InfoBox1.value
End Function
Function getFieldThree() As String
getFieldThree = InfoBox2.value
End Function
Function getFieldFour() As String
getFieldFour = InfoBox3.value
End Function
Function getFieldFive() As String
getFieldFive = InfoBox4.value
End Function
Function getChartTitle() As String
getChartTitle = ChartNameTextBox.value
End Function
Function getWhetherToSumFieldTwo() As Boolean
getWhetherToSumFieldTwo = SumFieldTwoCheckBox.value
End Function
----------------------------------------------------------------
Thanx in advance,
cLocKwOrk
-
what is the error your getting, what does it say?
-
Well I get the generic "Subscript out of Range" error
But when hovering over the ChartGenerator "varaible" (put in quotes since I never declared is as any sort of variable) I get "Object variable or With Block variable not set".
I tried this earlier:
Open "ChartGenerator" As Form
but that didn't work.
-cLocKwOrk
-
Btw... the debugger stops here for that error:
Sub GenerateUserCreatedChart()
Load ChartGenerator <----------------------ERROR
ChartGenerator.Show
End Sub
-
Try this...
Why don't you try this...
Code:
ChartGenerator.Load
ChartGenerator.Show
Or better without the load before the show, because when you
specify the .Show command if the form isn't loaded it will
automatically be loaded
Saludos...;)
-
The function ChartGenerator.Load was not defined by my code, therefore it cant be called since it is not a method of ChartGenerator.
As for removing it Load function completely and letting it autoload since "if the form isn't loaded it will
automatically be loaded". That doesn't seem to work either.
The debugging error (described above) just moves down to the ChartGenerator.Show line.
Any other ideas? (Oddly enough I dug up an older version that seems to work with the Load ChartGenerator and ChartGenerator.Show, maybe I changed some code within the Form itself that caused this).
In the meantime... basic form question: I don't have to Dim a variable that is a pointer to the form or some sort of reference to the form itself??? Just calling it's name seems rather sloppy.
-cLocKwOrk
-
I would check on that older code to see if there is indeed something differnet, and no, you don't have to dim a variable, just saying "FormName.Show" or "Load FormName"(minus the quotes, of course) is normally all you would need.
-
stupid question, but...
Is ChartGenerator spelled the same throughout your project?
What I mean is, you don't have the form named
"ChartGenarator", and then call it with
"ChartGenerator", or something like that?
-
Ok sweet. Thanx for clarifying that crptblade.
I did find out what was causing it... really weird.
Well I renamed some of the tabs (worksheet tabs) in the template. It seems that, for some reason, since I created all of the controls for the form when the tabs were named one way and then changed the tab names a debug error happens. No idea why.. but I created another Form that was blank and tried to Load it instead of my ChartGenerator form and it worked fine.
(I also tried naming the tabs back to their old names and that also worked... allowing ChartGenerator to work)
So yea.. I found the problem, but what a weird little "solution".
Thanx for all the feedback guyz,
cLocKwOrk
-
No problem...