ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   date update in VBA (https://www.excelbanter.com/excel-programming/358851-date-update-vba.html)

L Scholes

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?


mrice[_4_]

date update in VBA
 

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


--
mrice


------------------------------------------------------------------------
mrice's Profile: http://www.excelforum.com/member.php...o&userid=10931
View this thread: http://www.excelforum.com/showthread...hreadid=532743


Carim

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


L Scholes

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.


Tom Ogilvy

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.



L Scholes

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.


dok112[_139_]

date update in VBA
 

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 tha
you're wanting to activate

--
dok11
-----------------------------------------------------------------------
dok112's Profile: http://www.excelforum.com/member.php...fo&userid=1058
View this thread: http://www.excelforum.com/showthread.php?threadid=53274


L Scholes

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!!!



All times are GMT +1. The time now is 05:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com