Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

update access form field when checked

Posted on 2014-03-12
6
Medium Priority
?
539 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 39

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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 85
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 39

Accepted Solution

by:
PatHartman earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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 …

664 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