Solved

update access form field when checked

Posted on 2014-03-12
6
520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 37

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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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 37

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
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 the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

734 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