Solved

update access form field when checked

Posted on 2014-03-12
6
515 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
ID: 39925022
place this in click event code
if contacted then contactdate = datevalue(Now()) else contactdate =NULL
0
 
LVL 36

Expert Comment

by:PatHartman
ID: 39925548
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
ID: 39925588
'if contacted = true' is redundant,
if contacted then contactdate = date() else contactdate =NULL
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 84
ID: 39926032
'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 36

Accepted Solution

by:
PatHartman earned 500 total points
ID: 39926500
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
ID: 39932414
Very well explained, Pat.  I agree.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

828 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