MS Access Form Textbox

I have two textboxes on a form in continuous forms.  Starttime and Endtime.  I need to make my Starttime on the second line to be the same as the Endtime on the first line.  How can I do this?
deer777Asked:
Who is Participating?
 
Dale FyeConnect With a Mentor Commented:
another alternative would be to use the Form_BeforeUpdate event to capture the value in your [EndTime] column (or control).  To do this, you would have to declare a form level variable.
Private dtEndTime as date

Open in new window


Then use code similar to:
Private Sub Form_BeforeUpdate

    if me.NewRecord then
        dtEndTime = me.txt_EndTime
    else
        dtEndTime = NULL
    endif

End Sub

Open in new window

Then use the Form_Current event to check for a new record and if so, set the Value of [StartTime]
Private Sub Form_Current()

    if me.NewRecord then me.txt_StartTime = dtEndTime

End Sub

Open in new window

0
 
Dale FyeCommented:
You could use the AfterUpdate of the EndTime field to set the Default value of the StartTime field, but I would only do this when the record you are editing the EndTime on is a newrecord

Private Sub txt_EndTime_AfterUpdate

    if me.newrecord then
        me.txt_StartTime.DefaultValue = me.txt_EndTime
   Else
        me.txt_StartTime.DefaultValue = NULL
   End If

End Sub

Open in new window

0
 
deer777Author Commented:
I get a #Name? error in the StartTime field of the second record???
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Obviously you'd have to make sure you're using the right Control names and such. Dale's code would only work if you have controls named "txt_StartTime" and "txt_EndTime"
0
 
deer777Author Commented:
Yes I updated the controls accordingly.  I must be missing something because it updates automatically but only displays "#Name?" instead of the value
0
 
deer777Author Commented:
Worked perfect!  Thanks Dale!!
0
 
Dale FyeCommented:
glad I could help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.