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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default date to depend on another textbox

Status
Not open for further replies.

NeedsHelp101

Technical User
Jul 18, 2006
43
US
Hi,
I have two text boxes in my form, "boxWeekBegins" and "boxWeekEnds." I'm trying to make boxWeekEnds default to =[boxWeekBegins]+6, by putting this in the Properties-> Data -> Default Value space, but for some reason, when I open the form and enter a value in for boxWeekBegins, boxWeekEnds remains blank.
Tips?
Thanks!
 
=[boxWeekBegins]+6 should be the Control Source, not the default value.

Randy
 
Thank you, Randy, your suggestion worked perfectly. Now, however, I'm running into problems because I set boxWeekBegins to bring up a calendar and to enter the value the user chooses. If the user decides on a date for WeekEnds that's not the default date, I get an error.
I understand that what I need to do is to somehow clear the value, and then assign it the one chosen on the calendar. I wrote the following code to take care of it but am stuck on one part (it's in bold). Suggestions?


Code:
Private Sub Calendar_Click()
    If IsNull(boxWeekEnds) Then
        boxWeekEnds.Value = Calendar.Value
    Else
        boxWeekEnds [b]'clear then set to calendar value??[/b]
    End If
    
    boxWeekEnds.SetFocus
    Calendar.Visible = False
    Set boxWeekEnds = Nothing
    
End Sub

 
Let's see if I understand this correctly. Under normal circumstances, the boxWeekEnds date will be 6 days after the boxWeekBegins date. But, you want to allow the user to set a different date in boxWeekEnds, regardless of the boxWeekBegins date. Is that correct?

If so, I'd remove everything from the default value and control source of boxWeekEnds and set them in code.

Code:
Private Sub boxWeekBegins_AfterUpdate()
   me.boxWeekEnds = me.boxWeekBegins +6
End Sub

Private Sub Calendar_Click()
    me.boxWeekEnds = Calendar.Value
End Sub


Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top