Solved

update access form field when checked

Posted on 2014-03-12
6
506 Views
Last Modified: 2014-04-07
I have a form with two fields

contacted - a checkbox
contactdate - a date field

i need to update the contactdate to today's date when contacted is checked

Something like this code
Private Sub Contacted_AfterUpdate()
Set contactdate = Date
End Sub

Open in new window


any help would be appreciated
0
Comment
Question by:damixa
6 Comments
 
LVL 7

Expert Comment

by:COACHMAN99
Comment Utility
place this in click event code
if contacted then contactdate = datevalue(Now()) else contactdate =NULL
0
 
LVL 34

Expert Comment

by:PatHartman
Comment Utility
I would use Date() if I only wanted the date to be stored and Now() if I wanted both date and time.

If Contacted = True then 
    ContactedDate = Date()
Else
    ContactedDate = Null
End If

Open in new window

0
 
LVL 7

Expert Comment

by:COACHMAN99
Comment Utility
'if contacted = true' is redundant,
if contacted then contactdate = date() else contactdate =NULL
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 84
Comment Utility
'if contacted = true' is redundant,
True, but then inline IF - THEN statements are very difficult to read and troubleshoot downstream in massive code blocks.
0
 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
Comment Utility
Yes "= True" is redundant but I prefer to write code that people can read without having to interpret it.  I don't do "elegant", I don't do "slick", I don't use tricks, I don't take shortcuts.  I do mundane, readable/understandable for the novice code.  If there were some efficiency to be gained, I would use the shorthand but I doubt you could prove a difference in speed without executing the statement thousands of times.  And it is as likely that the shorthand would loose as win.  So, unless something is inside a loop where it will be executed thousands of times, plain, simple, straightforward, redundant is the code of the day.

When I was learning how to program in the late 60's and early 70's, the prerequisite for taking the advanced COBOL class was taking Assembler.  The idea behind that was you needed to understand what the compiler was going to do with what you wrote in COBOL in order to write efficient code.  Remember, it is not the source code of any language that is executed, it is the machine code generated by the compiler or in the case of VBA, which is an interpreted language, the pcode.  When I worked in COBOL, I could see the Assembler code (one step above the actual machine code) generated by the compiler.  So, I was able to determine if different techniques produced different Assembler code.  Programmers today don't have a clue what lies beneath their language of choice.  They never get to see the code that will actually be executed.  I would venture to say that there is ultimately no difference between using "=true" and omitting it.  The only difference would be in how long it takes the interpreter each time it encounters each statement to come up with the same executable pcode because the executable code would be identical.  And in how easy each statement is for the average user to understand.
0
 
LVL 12

Expert Comment

by:jkaios
Comment Utility
Very well explained, Pat.  I agree.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now