By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,576 Members | 1,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,576 IT Pros & Developers. It's quick & easy.

Setting a field to today's date

sueb
100+
P: 379
I would have thought that this operation would be simple:
Expand|Select|Wrap|Line Numbers
  1. Me.IUR_DATE.Value = DATE()
but the parentheses simply refuse to remain.

(Although I've been a programmer for 20 years, I'm finding Access really murky. Is it just me? That would be depressing...)

Anyway, here's the context:
Expand|Select|Wrap|Line Numbers
  1. Private Sub CLEAR_IUR_1_Click()
  2. On Error GoTo Err_CLEAR_IUR_1_Click
  3.  
  4.     Dim ctl As Control
  5.  
  6.     For Each ctl In Me.Controls
  7.       If ctl.Tag = "Clear" Then
  8.          ctl.Value = Null
  9.       End If
  10.     Next
  11.  
  12.     Me.IUR_DATE.Value = DATE
  13.  
  14. Exit_CLEAR_IUR_1_Click:
  15.    Exit Sub
  16.  
  17. Err_CLEAR_IUR_1_Click:
  18.     MsgBox Err.Description
  19.     Resume Exit_CLEAR_IUR_1_Click
What am I not understanding about this syntax?

Thanks!
May 3 '10 #1

✓ answered by NeoPa

Sue,

It looks to me very much like some other object is defined, and available to your database, with a name of DATE. If it were being recognised as the Date() function (from the VBA library) then only the D would be capitalised. Do you know how to use the Object Browser (See Debugging in VBA) to find what is declared where?

As Linq intimated earlier, your code has no obvious bug in it. What you have should normally work.

Share this Question
Share on Google+
13 Replies


missinglinq
Expert 2.5K+
P: 3,532
Yes, Access VBA will remove the parens in some instances, but it doesn't affect the code, it should still work.

IMHO, Access VBA is no 'murkier' than any other language; they all have their quirks! The important thing to understand, especially for programmers who have worked previously in straight Visual Basic, is that VBA is a different language. Many things are the same, but many functions, even those with similar or even identical names, perform differently.

Linq ;0)>
May 4 '10 #2

sueb
100+
P: 379
I've never worked in "straight Visual Basic"--my time was spent mostly with Ada.

Be that as it may, the very reason I'm posting the question is because it DOESN'T work. My date field does not get set to today.
May 4 '10 #3

100+
P: 283
Are you trying to make the field and autodate feature? Where it will put the date in for you instead of someone one having to key in the date.

If that is the case all you need is in the properties for the text box (on your form) you are using put this in the default value field

Expand|Select|Wrap|Line Numbers
  1. =Int(Now())
  2.  
Then you can actually sent the text box to not visible link it to your table and it will automatically save todays date to your table every time something is entered.
hope that helps
May 4 '10 #4

sueb
100+
P: 379
Not exactly. I need the field to be set when the user takes a specific action (clicks a little button that is on the form) rather than when there record is created.
May 4 '10 #5

NeoPa
Expert Mod 15k+
P: 31,769
Sue,

It looks to me very much like some other object is defined, and available to your database, with a name of DATE. If it were being recognised as the Date() function (from the VBA library) then only the D would be capitalised. Do you know how to use the Object Browser (See Debugging in VBA) to find what is declared where?

As Linq intimated earlier, your code has no obvious bug in it. What you have should normally work.
May 4 '10 #6

sueb
100+
P: 379
@NeoPa
That makes real sense. I'll look around, but on the good chance that that is actually the case, I know that I'll not want to mess that object, so how can I specify here that what I want is the Date from the VBA library and not any other?
May 4 '10 #7

missinglinq
Expert 2.5K+
P: 3,532
but on the good chance that that is actually the case, I know that I'll not want to mess that object, so how can I specify here that what I want is the Date from the VBA library and not any other?
You can't! You simply have to change the name of the object to something other than Date!

Linq ;0)>
May 4 '10 #8

sueb
100+
P: 379
@missinglinq
Wait, what?? You mean the language doesn't support overloaded names and the ability to specify which you want?
May 4 '10 #9

NeoPa
Expert Mod 15k+
P: 31,769
It does to a certain extent, but Date is a fundamental part of the basic setup. It is always recommended very strongly not to overload such items due to the confusion they will necessarily cause.

In this case, it is possible, but I repeat not a recommended solution, to use VBA.Date.
May 4 '10 #10

sueb
100+
P: 379
What are the pitfalls, in this case, of using specific notation to access VBA's date function?
May 4 '10 #11

NeoPa
Expert Mod 15k+
P: 31,769
None, as such Sue.

The pitfalls generally are associated with reusing common names in a project. Reading and understanding what is going on is always likely to be harder when there is any possibility of ambiguity. Using VBA.Date() is not ambiguous, but having some object called DATE is likely to be. Does that clarify?
May 4 '10 #12

sueb
100+
P: 379
I totally agree, but since I'm just maintaining this databse (and part-time at that!) I just wanted to know how I could specify that I wanted to access the system date and not whatever function some previous developer overloaded that name with.

Thanks to you, I can now do that!

(This site is wonderful!)
May 5 '10 #13

NeoPa
Expert Mod 15k+
P: 31,769
It's always pleasant to read such responses. You're welcome of course :)
May 5 '10 #14

Post your reply

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