+ Reply to Thread
Results 1 to 8 of 8

date update in VBA

  1. #1
    L Scholes
    Guest

    date update in VBA

    I have two date boxes on a user form, txtDate and txt Due. Both have
    check boxes that are default "false." I would like the txtDue to become
    "true" when I check txtDate and automatically assume the same date as
    txtDate. How do I accomplish this?


  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Response

    Why not set the value property of the second box to try as part of the change method of the first.
    Martin

  3. #3
    Carim
    Guest

    Re: date update in VBA

    Hi,

    By coding your check box1 ...
    Private Sub CheckBox1_Click()
    CheckBox2.Enabled = True
    CheckBox2.Value = CheckBox1.Value
    End Sub
    be sure to adjust with your names ...

    HTH
    Carim


  4. #4
    L Scholes
    Guest

    Re: date update in VBA

    Carim's method works, but it only enables txtDue when I click
    txtDate. I actually want txtDue to stay disabled until I click it, I
    just want it's value to change to the value in txtDate when I enable
    it. (I dont always use a Due Date, but if I do it is generally the next
    day or two, so it is easier to start from the Date.)(If that is clearer
    than mud.)

    I don't know how to follow mrice's advice. I tried to set the
    value in txtDue to "txtDate" and get an error message. (???)

    I appreciate your help.


  5. #5
    Tom Ogilvy
    Guest

    Re: date update in VBA

    if txtDate and txtDue are checkboxes and txtDue has the enabled property set
    to false when the userform is shown. then you want to click one the area of
    the disabled checkbox and have it come to life and take on the value of the
    checkbox txtDate, then you can use this:

    Private Sub UserForm_MouseDown(ByVal Button _
    As Integer, ByVal Shift As Integer, _
    ByVal X As Single, ByVal Y As Single)
    With txtDue
    If Y >= .Top And Y <= .Top + .Height Then
    If X >= .Left And X <= .Left + .Width Then
    .Enabled = True
    .Value = txtDate.Value
    End If
    Else
    End If
    End With

    End Sub

    --
    Regards,
    Tom Ogilvy



    "L Scholes" wrote:

    > Carim's method works, but it only enables txtDue when I click
    > txtDate. I actually want txtDue to stay disabled until I click it, I
    > just want it's value to change to the value in txtDate when I enable
    > it. (I dont always use a Due Date, but if I do it is generally the next
    > day or two, so it is easier to start from the Date.)(If that is clearer
    > than mud.)
    >
    > I don't know how to follow mrice's advice. I tried to set the
    > value in txtDue to "txtDate" and get an error message. (???)
    >
    > I appreciate your help.
    >
    >


  6. #6
    L Scholes
    Guest

    Re: date update in VBA

    I want both to be disabled when the userform is initally activated in
    case I dont need the dates. I will have to enter a date, but not always
    a due date, so I want them to activate independantly, but when I
    activate txtDue, I want it to assume the same date as txtDate instead
    of todays date. Not critical, but because the due date is always close
    to the date it will be faster to start from the date instead of today.
    I would try to use your method, but I'm not even sure where in my
    current code to place it; I am trying now, after posting this.


  7. #7
    Forum Contributor
    Join Date
    06-13-2004
    Posts
    120
    This I think is what you're wanting. If not let me know.

    Private Sub CheckBox1_Click()
    If CheckBox1.Value = True Then
    CheckBox2.Value = True
    textbox2.Value = textbox1.Value
    Else:
    CheckBox2.Value = False
    textbox2.Value = Date
    End If
    End Sub


    Adjust the names to your's and put the code under the checkbox that you're wanting to activate.

  8. #8
    L Scholes
    Guest

    Re: date update in VBA

    txtDate and txt due are both DTPickers and the "CheckBox" value is set
    to "true" so there is a check box inside the box to activate the date,
    i.e. no check box = no date, check box = date. I have the checkbox set
    to be false by default so it won't print unless I ask it to, but I want
    the default date to be the same as the date selected in txtDate when it
    is activated. Your code has "checkbox1 & 2" but there are no separate
    checkboxes.
    I do appreciate your help!!!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1