Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Calling Sub from onClick event causes "application-defined or object-defined error"

Posted on 2016-08-25
5
40 Views
Last Modified: 2016-09-26
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.Value <> "" 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(useCategoryFilter, useCountryFilter, useBoth, UserForm1.cmbCategory.Value, 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
0
Comment
Question by:Anton Vandeghinste
  • 2
5 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 41771193
Is this in Access or Excel? Where abouts is the CreateChart routine located? Is it in the same workbook? Is it Public?

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...

CreateChart useCategoryFilter, useCountryFilter, useBoth, UserForm1.cmbCategory.Value, UserForm1.cmbCountry.Value

Open in new window

0
 

Author Comment

by:Anton Vandeghinste
ID: 41771357
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...
0
 

Accepted Solution

by:
Anton Vandeghinste earned 0 total points
ID: 41771379
This Question is solved, turns out i was being stupid... The error showed on the line where I called the Sub, but it actually occurs inside the routine itself, i've figured it out!

Thanks for the help anyway!
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 41815706
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
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question