469,286 Members | 2,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

Run-time error '2763' setting date/time picker value.

8,435 Expert 8TB
Hi all.

I have a couple of dtpicker controls on a form. When one is changed by the user (that's me, in this case) the code in the _Change event sets the other one, to keep it within a logical range (can't start a task before it's requested).

I know I had this working, but don't recall for certain what has changed. Anyway, it is now causing
Expand|Select|Wrap|Line Numbers
  1. Run-time error '2763':
  2.  
  3. DTPicker returned the error: An error occurred in a call to the Windows
  4. Date and Time Picker control..
I've been doing some searching on TSDN and elsewhere, without success so far.

Oh, just had a thought. Is it possible I'm just running into the old silliness of not being able to address the properties while the control is hidden? I'll test that and get back to you.
Jan 22 '07 #1
26 12250
Killer42
8,435 Expert 8TB
Damn! That was it.

I still can't believe Access VBA is so stupid it can't change a property of a hidden control. :( Now I'll have to rewrite all my code to show the control, change it, then re-hide it - but only if it was hidden to start with. Grrr...
Jan 22 '07 #2
nico5038
3,080 Expert 2GB
You can keep the control visible, but use a rectangle on top and manage the visibility of that to reveal the dtpickers.

Nic;o)
Jan 22 '07 #3
Killer42
8,435 Expert 8TB
You can keep the control visible, but use a rectangle on top and manage the visibility of that to reveal the dtpickers.
Sneaky - I like it! :)
Jan 22 '07 #4
Killer42
8,435 Expert 8TB
Sneaky - I like it! :)
Argh!

How can I cover up the dtpicker? I've tried placing a label and an option group over it. They can both cover up the label, but the actual picker control shows through them. (Yes, I have them set to "normal", not transparent).

I can't seem to create a unbound object frame without placing an object in it, or an image control within putting an image in it. I keep trying things that are perfectly simple in VB6, and running into limitations in Access. :(

I suppose if necessary I can create a small image using the same colour as my background, but what if the colour scheme changes? And will the image control work as a cover? I'll have to test it - hopefully some time today.

Any other ideas for a "lid" control I can put over my dtpickers? I love the idea, but so far the implementation is proving to be a real pain.
Jan 22 '07 #5
Killer42
8,435 Expert 8TB
P.S. The various controls that I tried did cover up the dtpicker at design time, but at runtime, no-go.
Jan 22 '07 #6
nico5038
3,080 Expert 2GB
And hiding the form, then set the dtpickers and then show the form ?

Nic;o)
Jan 22 '07 #7
Killer42
8,435 Expert 8TB
And hiding the form, then set the dtpickers and then show the form ?
Interesting idea, but not likely to be an option in this case. Each click to a datepicker adjusts others to keep them in synch.

This is starting to feel just like MS Word - you know, the way it seems to be designed to prevent you finding any way to do what you want to do. No matter which way you turn, they've found some way to cut off that approach. :(
Jan 23 '07 #8
Killer42
8,435 Expert 8TB
In this case, I think I'm going to go back to my original technique, hiding and showing the dtpickers. But rather than setting their Value directly, I'll pass the control and the new value to a routine which performs this logic
Expand|Select|Wrap|Line Numbers
  1. Hold the value of .Visible property
  2. If it's hidden Then
  3.   Set .Visible to True
  4. End If
  5. Set .Value to passed value
  6. If it was originally hidden Then
  7.   Set .Visible = False
  8. End If
Seems a bit of an ugly solution, but I think it should work. I'm thinking of also passing the property name, so I can use it for things other than .Value.
Jan 23 '07 #9
Killer42
8,435 Expert 8TB
...I'm thinking of also passing the property name, so I can use it for things other than .Value.
Well, what a surprise! It didn't work.

I expect it will work alright if I use the original routine to explicitly set the .Value property, but when I passed the string "Value" and tried to set control.Properties(PropName) I got run-time error '2455': You entered an expression that has an invalid reference to the property Value.

Sigh... :(
Jan 23 '07 #10
Killer42
8,435 Expert 8TB
I've changed my code to invoke a new sub which works as outlined above. It's not elegant, but appears to work.

Since hiding the dtp's behind another control didn't pan out, I was thinking, maybe I could leave them visible but shift them off-screen. Can't take the time to go into it now, though. (I'd need to play with things like Tab Stop and so on.)
Jan 23 '07 #11
NeoPa
32,173 Expert Mod 16PB
Try this :
Expand|Select|Wrap|Line Numbers
  1. 'SetVal sets the value of a control even if it's hidden.
  2. Public Sub SetVal(ctlThis As Control, varValue As Variant)
  3.     Dim blnVisible As Boolean
  4.  
  5.     With ctlThis
  6.         blnVisible = .Visible
  7.         .Visible = True
  8.         .Value = varValue
  9.         .Visible = blnVisible
  10.     End With
  11. End Sub
I don't know if this is a lot more elegant than your version but it certainly worked for me (except I didn't set up a DT Picker control - just tested it on a TextBox).
Jan 23 '07 #12
nico5038
3,080 Expert 2GB
Ever though to switch to an all Access calendar like the one from:
http://www.mvps.org/access/forms/frm0050.htm
(keep shift pressed, otherwise there's an error...)

Nic;o)
Jan 23 '07 #13
Killer42
8,435 Expert 8TB
...I don't know if this is a lot more elegant than your version but it certainly worked for me (except I didn't set up a DT Picker control - just tested it on a TextBox).
No offence, but I'm not going to bother trying. During testing on the DTPicker, one of the things I tried placing over it was a text box. The DTPicker just seems to bust through everything, including textboxes.

For now I'm just going to go with my current solution, which looks as though it works, even if it is ugly behind the scenes. It's not worth rewriting over and over.

Actually, now that I come to read it, your solution is the same one I'm using. The only difference is that I'm testing the visibility and only changing it when necessary. I've always been under the impression that setting control properties is slow compared to reading them or playing with variables, and so avoid it whenever possible.
Jan 23 '07 #14
Killer42
8,435 Expert 8TB
Ever though to switch to an all Access calendar like the one from: http://www.mvps.org/access/forms/frm0050.htm
(keep shift pressed, otherwise there's an error...)
Thanks for that Nico. I'll be curious to have a look at it, when I can find time. But for now I'll be sticking with the workaround I've got, since it has the advantage of already having been done. :)
Jan 23 '07 #15
nico5038
3,080 Expert 2GB
No thanks needed :-)
I stopped using the dtpicker as it won't work on all PC's. In general I try to work without ocx controls as much as possible to limit dependencies to the .dll hell :-)

With A2007 this trouble is "solved" as every date datatype will get a calendar control automatically.

Nic;o)
Jan 23 '07 #16
Killer42
8,435 Expert 8TB
...With A2007 this trouble is "solved" as every date datatype will get a calendar control automatically.
I don't suppose they've overcome the old 2GB limitation? Even 4GB would be some improvement.
Jan 23 '07 #17
nico5038
3,080 Expert 2GB
Not that I know of. Guess they won't do much effort for the Jet engine as they want to sell MS SQL <LOL>

Nic;o)
Jan 23 '07 #18
Killer42
8,435 Expert 8TB
Not that I know of. Guess they won't do much effort for the Jet engine as they want to sell MS SQL
Yeah, that's what I figured.
Jan 23 '07 #19
NeoPa
32,173 Expert Mod 16PB
No offence, but I'm not going to bother trying. During testing on the DTPicker, one of the things I tried placing over it was a text box. The DTPicker just seems to bust through everything, including textboxes.

For now I'm just going to go with my current solution, which looks as though it works, even if it is ugly behind the scenes. It's not worth rewriting over and over.

Actually, now that I come to read it, your solution is the same one I'm using. The only difference is that I'm testing the visibility and only changing it when necessary. I've always been under the impression that setting control properties is slow compared to reading them or playing with variables, and so avoid it whenever possible.
That's fine Killer.
I didn't get to see your code so didn't know what you'd come up with.
I worked on the basis that as a form is user operated, the efficiency of the routine (with unnoticeable levels of delay) was secondary to the tidyness of the code. You obviously have something just as good already (No surprise there really :)) so that's ok.
Jan 23 '07 #20
Killer42
8,435 Expert 8TB
...I didn't get to see your code so didn't know what you'd come up with.
What's that? Posting without reading everything first? I'm shocked! ;)
Jan 23 '07 #21
NeoPa
32,173 Expert Mod 16PB
I saw your pseudo-code, the outline thinking.
Wasn't sure what you actually came up with.
Jan 23 '07 #22
Killer42
8,435 Expert 8TB
I saw your pseudo-code, the outline thinking.
Wasn't sure what you actually came up with.
Ah. Well, in the end I copied the pseudo-code pretty closely. Um.. hang on...
Expand|Select|Wrap|Line Numbers
  1. Public Sub Set_DTP_Value(ctl As Control, ByVal NewValue As Date)
  2.   ' Since I have so much trouble setting the value of my datetimepicker
  3.   ' controls due to this exteremely annoying and STUPID limitation
  4.   ' in Access that they have to be visible, I've written this litte
  5.   ' generic routine to take a datetimepicker (actually, it will accept
  6.   ' any type of control, but I don't recommend it) and set the value,
  7.   ' turning the visibility on and off as required to (A) allow the change,
  8.   ' and (B) maintain the controls original state.
  9.   Dim HoldVis As Boolean
  10.   With ctl
  11.     HoldVis = .Visible
  12.     If Not HoldVis Then
  13.       .Visible = True
  14.     End If
  15.     .Value = NewValue
  16.     If Not HoldVis Then
  17.       .Visible = False
  18.     End If
  19.   End With
  20. End Sub
As you can see, I'm pretty verbose when it comes to comments. What a surprise! :)

I considered putting some extra code in to safeguard against going outside of the MinDate and MaxDate range, but in the end I didn't bother. There's so much shuffling around of values (with attendant errors due to the aforementioned range limit) that in the end I just set the min and max 'way off in the past and future and left them there.

Of course, the nice thing about having the value-change encapsulated here is that it will be that much simpler (hopefully) if I do decide to modify the method.
Jan 23 '07 #23
NeoPa
32,173 Expert Mod 16PB
Like the comments ;)
Bear in mind the type of your value parameter (NewValue) for fully generic use.
Jan 23 '07 #24
Killer42
8,435 Expert 8TB
Like the comments ;)
Bear in mind the type of your value parameter (NewValue) for fully generic use.
In the generic "name the property" version (see copy below), I used Variant for the value type. Normally I hate variants (probably a sign of age :)) though I guess they do have their uses. But as long as the data type is known (as it is here) I prefer to use it. Oh, I meant to ask - what would be the correct type to use for the dtpicker. In my "real" routine (the one with the long comments) I only used the generic "As Control" because I didn't know the right type.


Expand|Select|Wrap|Line Numbers
  1. Public Sub SetValue(ctl As Control, ByVal Prop As String, ByVal NewValue As Variant)
  2.   Dim HoldVis As Boolean
  3.   With ctl
  4.     HoldVis = .Visible
  5.     If Not HoldVis Then
  6.       .Visible = True
  7.     End If
  8.     .Properties(Prop) = NewValue
  9.     If Not HoldVis Then
  10.       .Visible = False
  11.     End If
  12.   End With
  13. End Sub
Jan 23 '07 #25
NeoPa
32,173 Expert Mod 16PB
I like that code :)
I wasn't sure you could do that generically but you found a good way.
DTPicker controls - I don't know what they are. ...But if you add a watch to one (or even just to the form) then, when the code is active (in break mode) you can see the type in the Watch Window.
Jan 23 '07 #26
Killer42
8,435 Expert 8TB
I like that code :)
I wasn't sure you could do that generically but you found a good way.
Thank you. However, if you read an earlier post in this thread, you'll see that it didn't work. But I don't know why.
DTPicker controls - I don't know what they are. ...But if you add a watch to one (or even just to the form) then, when the code is active (in break mode) you can see the type in the Watch Window.
Good point. I'll give it a shot.
Jan 23 '07 #27

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by leroybt.rm | last post: by
15 posts views Thread by mg | last post: by
9 posts views Thread by shank | last post: by
19 posts views Thread by Bryan | last post: by
9 posts views Thread by Brett Wesoloski | last post: by
7 posts views Thread by mxdevit | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.