Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

capture the date when a user clicks on a button for the 1st time. 1

Status
Not open for further replies.

ruthcali

Programmer
Apr 27, 2000
470
US
i would like to capture the date when a user first clicks on a command button. i can't use =now() because that is updated all the time. i am only interested in the date when the user FIRST clicks on the button. <br><br>any suggestions?
 
for the OnClick property try some code as such:<br><b><br>If IsNull(FieldName) Then<br>Me.FieldName.Value = Now()<br>End IF<br></b><br><br>haven't tried this, but it should work.&nbsp;&nbsp;just replace &quot;FieldName&quot; with the name of the field that you want to capture the data in.<br>if that field is Null, then the date will be inserted, otherwise it will keep the current value<br> <p>Brian Famous<br><a href=mailto:bfamous@ncdoi.net>bfamous@ncdoi.net</a><br><a href= > </a><br>
 
it doesn't work. here is my code:&nbsp;&nbsp;<br><br>If IsNull(Day1CreateTime) Then<br>&nbsp;&nbsp;&nbsp;Forms![frmDay1].[Day1CreateTime].Value = Now<br>Else<br>&nbsp;&nbsp;&nbsp;End<br>End If<br><br>if i bind the text box (Day1CreateTime) to my table, i get a run time error message 'You can't assign a&nbsp;&nbsp;value to this object'.<br><br>if i create the text box as an unbound text box, i keep getting the current date and time.&nbsp;&nbsp;in other words, the isnull doesn't work. i have also tried:<br><br>If [Day1CreateTime].Value &lt;&gt; &quot;&quot; Then<br>&nbsp;&nbsp;End<br>Else<br>&nbsp;&nbsp;&nbsp;Forms![frmDay1].[Day1CreateTime].Value = Now<br>End If<br><br>but that doesn't work. please help!
 
so Day1CreateTime isn't a field on the form with the button to set the date? or is it?<br>If it isn't then try to do your code like such:<br><b>If IsNull(Forms![frmDay1].[Day1CreateTime]) Then<br>&nbsp;&nbsp;&nbsp;Forms![frmDay1].[Day1CreateTime].Value = Now<br>End If<br></b><br><br>but, you might also have to do an OpenForm statement to allow you to append to that table.<br><br>try putting this line first:<br><b><br>DoCmd.OpenForm &quot;frmDay1&quot;, acNormal, , , acFormAdd, acHidden<br></b><br>and then this line after:<br><b><br>docmd.Close acForm, &quot;frmDay1&quot;<br></b><br> <p>Brian Famous<br><a href=mailto:bfamous@ncdoi.net>bfamous@ncdoi.net</a><br><a href= > </a><br>
 
This works for me in a bound field. Does your underlying bound field have a date field format? &quot;Now&quot; works for me too but Now actually captures time as well as date and can cause other problems.<br><br>If IsNull(Me!Day1CreateTime) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me!Day1CreateTime = Date<br>End If
 
thank you!!! it works.&nbsp;&nbsp;i had my code in the 'open event' of the second form (frmDay1).&nbsp;&nbsp;but, i moved it to the click event of the command button of the first form and it works.<br>thank you so much. i have spend many hours working and struggling with this. it is nice to know that other people care and are willing to help others. :)<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top