Solved

update access form field when checked

Posted on 2014-03-12
6
510 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 34

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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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 34

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

948 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

22 Experts available now in Live!

Get 1:1 Help Now