Anton Vandeghinste
asked on
Calling Sub from onClick event causes "application-defined or object-defined error"
Hi,
I try my best to tinker at VBA using fora like these alot. Now the "application-defined or object-defined error" is in my opinion the most vague one i've seen so far...
Basically I'm trying to call a Sub with given arguments from a UserForm dialog i created, the moment the user presses the OK button.
But everytime I run it I get the same error. The strangest thing is: when executing the line in the immediate window, it works just fine...
So here's the code(error line marked with -->):
Private Sub cmdOK_Click()
Dim useCategoryFilter, useCountryFilter, useBoth As Boolean
useCategoryFilter = False
useCountryFilter = False
useBoth = False
If UserForm1.cmbCategory.Valu e <> "" Then
useCategoryFilter = True
End If
If UserForm1.cmbCountry.Value <> "" Then
useCountryFilter = True
End If
If useCategoryFilter And useCountryFilter Then
useBoth = True
End If
--> Call ThisWorkbook.CreateChart(u seCategory Filter, useCountryFilter, useBoth, UserForm1.cmbCategory.Valu e, UserForm1.cmbCountry.Value )
UserForm1.Hide
End Sub
And then for the sub(due to classified data i cannot put the whole thing, but this one runs fine, when it does):
Sub CreateChart(ByVal useFilterCategory As Boolean, ByVal useFilterCountry As Boolean, ByVal useFilterBoth As Boolean, ByVal categoryFilter As String, ByVal countryFilter As String)
'Do some stuff here
End Sub
PS.: i looked on the first 3 pages on the forum with the search line "application-defined or object-defined error" but didn't seem to find anything that is suitable for my case? Excuse me if i am incorrect on that matter.
Thanks in Advance!
Anton
I try my best to tinker at VBA using fora like these alot. Now the "application-defined or object-defined error" is in my opinion the most vague one i've seen so far...
Basically I'm trying to call a Sub with given arguments from a UserForm dialog i created, the moment the user presses the OK button.
But everytime I run it I get the same error. The strangest thing is: when executing the line in the immediate window, it works just fine...
So here's the code(error line marked with -->):
Private Sub cmdOK_Click()
Dim useCategoryFilter, useCountryFilter, useBoth As Boolean
useCategoryFilter = False
useCountryFilter = False
useBoth = False
If UserForm1.cmbCategory.Valu
useCategoryFilter = True
End If
If UserForm1.cmbCountry.Value
useCountryFilter = True
End If
If useCategoryFilter And useCountryFilter Then
useBoth = True
End If
--> Call ThisWorkbook.CreateChart(u
UserForm1.Hide
End Sub
And then for the sub(due to classified data i cannot put the whole thing, but this one runs fine, when it does):
Sub CreateChart(ByVal useFilterCategory As Boolean, ByVal useFilterCountry As Boolean, ByVal useFilterBoth As Boolean, ByVal categoryFilter As String, ByVal countryFilter As String)
'Do some stuff here
End Sub
PS.: i looked on the first 3 pages on the forum with the search line "application-defined or object-defined error" but didn't seem to find anything that is suitable for my case? Excuse me if i am incorrect on that matter.
Thanks in Advance!
Anton
ASKER
It's excel, sorry i forgot to mention...
My setup is like this:
+VbaProject
+Microsoft excel-objects
-Sheet1
-Sheet2
-ThisWorkbook(this is where CreateChart is present)
+Forms
-UserForm1(this is where the onClick is
Concerning the protection of the Sub CreateChart, there is no keyword in front of it, so i'm assuming it's public...
EDIT: I tried your code without the brackets, but that gave me a syntax error...
My setup is like this:
+VbaProject
+Microsoft excel-objects
-Sheet1
-Sheet2
-ThisWorkbook(this is where CreateChart is present)
+Forms
-UserForm1(this is where the onClick is
Concerning the protection of the Sub CreateChart, there is no keyword in front of it, so i'm assuming it's public...
EDIT: I tried your code without the brackets, but that gave me a syntax error...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I have recommended this question be closed as follows:
Accept: Anton Vandeghinste (https:#a41771379)
If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.
frankhelk
Experts-Exchange Cleanup Volunteer
I have recommended this question be closed as follows:
Accept: Anton Vandeghinste (https:#a41771379)
If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.
frankhelk
Experts-Exchange Cleanup Volunteer
If it's Excel and the CreateChart routine is Public and in a regular Module of the same workbook as the form, you can call the routine like this...
Open in new window