473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Setting a field to today's date

sueb
379 256MB
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.

13 12324
missinglinq
3,532 Expert 2GB
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
379 256MB
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
slenish
283 100+
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
379 256MB
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
32,556 Expert Mod 16PB
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
379 256MB
@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
3,532 Expert 2GB
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
379 256MB
@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
32,556 Expert Mod 16PB
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
379 256MB
What are the pitfalls, in this case, of using specific notation to access VBA's date function?
May 4 '10 #11
NeoPa
32,556 Expert Mod 16PB
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
379 256MB
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
32,556 Expert Mod 16PB
It's always pleasant to read such responses. You're welcome of course :)
May 5 '10 #14

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

Similar topics

4
by: peashoe | last post by:
I have an asp page that uses a calendar.js (pop-up) file to add an exact date format in the text field (txtDDate). My problem is I need some javascript that sets an alert that does not allow them...
3
by: Lumpierbritches | last post by:
Can this be done in access by a lay person? Also, are there any tutorials for this type of addition to your applications? I'm trying to use a calendar control to set a date in the future for a to...
1
by: Anna | last post by:
I am an extreme newbie to Access and need help setting a default date on a form. The situation is: I have a field called date_received which is set to default to today's date. I have another...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
2
by: k.roberts | last post by:
I'm not sure if this is possible or even practical to do, but I have a database which logs customer enquiries and has a field for the status of the enquiry i.e. Received, Approved, Job start, Job...
11
by: walterbyrd | last post by:
My MySQL table has a field that is set as type "date." I need to get today's date, and insert it into that field. The default for that MySQL field is 2006-00-00. I know about the date()...
1
by: LostBoy | last post by:
Hello, I have been giving a big task to add some additional features to the Access DB at work. I am not the one who originally created the DB, which makes it harder. I am familiar with access but...
7
by: Techhead | last post by:
I have a date/time field with a sql format of "datetime" The actual date/time data format is MM/DD/YYYY^hh:mm:ss:pm or "1/25/2007 12:00:16 AM" Both the date and time are combined on the same field...
2
by: Luqman | last post by:
Hi, Any Idea how to Display Todays Date in DetailView Template Field while Inserting ? For example: When I click on New Button of DetailView Control, I need to display Today's Date in a...
3
by: Ciara9 | last post by:
I am having problems trying to update a field in a database using a field in a form. I currently have two fields, Today and Tomorrow in a table named Date. The Today field automatically defaults to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.