Results 1 to 9 of 9

Thread: [RESOLVED] Cancel = true error

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    8

    Resolved [RESOLVED] Cancel = true error

    Hi there,

    I have a code on a userform in which when the first combo box is empty, if the user try to access the second one then he/she will receives a msg box showing up telling him/her to go back to the first one. I have used a cancel=true code to terminate the access of the second box if the first box is empty.

    The problem with this is, it works on my computer and my friend's computer, but it didn't work on another friend's computer and the one I want to use the userform on. Why is this happening?

    btw, I am using excel 2007 and the friend's computer that worked use excel 2010, while the one not worked are also excel 2007 i think.

    Code:
    Private Sub cboEquipment_DropButtonClick()
    If cboIndustry.ListIndex < 0 Then
    MsgBox ("Please choose an Industry/Company"), vbInformation
    Cancel = True
    cboIndustry.SetFocus
    Exit Sub
    End If
    End Sub
    
    Private Sub cboEquipment_Enter()
    If cboIndustry.ListIndex < 0 Then
    MsgBox ("Please choose an Industry/Company"), vbInformation
    Cancel = True
    cboIndustry.SetFocus
    Exit Sub
    End If
    End Sub
    Thank you!

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Cancel = true error

    try exit sub instead
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Cancel = true error

    Why do you have exit sub within the conditional statement when there is nothing following after them? The way I see it is there is no point in using "exit sub" or "exit function" if you place on the last line of a sub or function.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Cancel = true error

    The way I see it is there is no point in using "exit sub" or "exit function" if you place on the last line of a sub or function.
    very true, my bad answer before
    to answer the original, there is no cancel parameter to the procedure so cancel is not valid, at best it would be an undeclared variable, using a reserved word for its name, in the current scope it would do nothing anyway, just omit that line
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Cancel = true error

    When you say "it didn't work" on another friend's computer, what does that mean? What did or didn't it do?

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    8

    Re: Cancel = true error

    Hi guys,

    Thank you for the suggestions.
    But the problem I now have is that this code gives me what I what to do (a msgbox show up to tell the user to select something from the first combo box and it will set the focus to the first combo box)
    Only that on the computer I want it to work that it will occur an error and the line cancel = true is the problem.
    I will try to remove the exit sub but I think the problem lies within the line cancel = true.
    Is there some kind of add-in function of something.
    Many Thanks!

  7. #7
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Cancel = true error

    If you step through the code, does it give you an error on that statement, or not?

    If so, what error number?

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    8

    Re: Cancel = true error

    hi vbfbryce,

    I just checked again on my frd's computer, but it is not in english so i can only say what it kind of means.
    It returns something like "could not find database" or something, and in the further information button i clicked, i think it says there is a .olb file missing or something like that.
    I don't know if you know what that means, because i don't see a error number or anything, thank you for helping me anyway, appreciate it.

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    8

    Re: Cancel = true error

    hi all,

    Thank you for replying, I found a solution online, I need to go to tools --> references to untick the missing bits because some computers might not have the same add-ins as mine but will be ticked as default and would be missing from other computers that doesnt have this add-ins, just untick the box with missing would do the job. Still thanks for the replies!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width