Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Xl2003: Validation.Add method gives error from Command Button

This seems to be one of the weirdest, worst methods in the whole darn'
Excel VBA town, judging by the number of posts about it.

I THINK I've worked out why I keep getting Error 1004: Application
defined or object error. Here's the code:

Set objDBCell = ActiveWorkbook.Names("Setting_DB").RefersToRange
With objDBCell.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:=strListRange
.IgnoreBlank = False
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Invalid entry"
.InputMessage = ""
.ErrorMessage = "A value from the list must be selected"
.ShowInput = False
.ShowError = True
End With

strListRange, in my tests, is

=$A$20:$A$30

Now this works IF I run the procedure (which is in a general module,
following a suggestion in another topic on this subject) from the
Immediate window.

But if it runs from the Click event of a Control Toolbox command
button, it fails on the .Add line, with that inscrutable "1004" error.

Now I just remembered there's another command button, off the Forms
toolbar. With that command button, it works fine!

So, problem solved, for me. But it seems the validation.Add method is
hypersensitive to what actually calls the code that includes it.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Xl2003: Validation.Add method gives error from Command Button

Oh and BTW, who had the bright idea of making data validation lists
have to be on the same worksheet as the validated cell, in XL2003,
when you could have them on any worksheet in XL2000?

  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Xl2003: Validation.Add method gives error from Command Button

If you give your list a name (e.g., ID_Num), then you can place it on a
different worksheet. In the validated cell, set Source: =ID_Num.
Bob


"sebt" wrote:

Oh and BTW, who had the bright idea of making data validation lists
have to be on the same worksheet as the validated cell, in XL2003,
when you could have them on any worksheet in XL2000?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem face in Validation Command (Pop-up Error Box) Nono Excel Worksheet Functions 1 September 3rd 07 01:38 PM
Command Button Error - Help Needed Urgently Please Salman Excel Worksheet Functions 2 March 7th 07 10:24 AM
Error When Assigning a Macro to a Command Button Gavin Ayling Excel Programming 0 January 24th 07 04:24 PM
Command Button run-time error Dominique Feteau Excel Programming 1 June 29th 04 02:57 AM
Run-time error on command button Phil Hageman[_3_] Excel Programming 4 November 4th 03 08:06 PM


All times are GMT +1. The time now is 11:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"