Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Maybe something like:
Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
in my code please ignore the first section as it is headed with ' (I was just
trying that out). So the code I am using and that does not work is: Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") tia James "access user" wrote: Hi Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
assuming that the objects are on teh same form, then you don't really need
ther "me" thing Private Sub Calendar1_Click() Label1.Caption = Format$(Calendar1.Value, "ddd mm yyyy") End Sub "access user" wrote: in my code please ignore the first section as it is headed with ' (I was just trying that out). So the code I am using and that does not work is: Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") tia James "access user" wrote: Hi Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Is txtPeriodFrom a textbox on that same form?
Me.txtPeriodFrom.Value = Format(Calendar1.Value, "mmmm dd, yyyy") I still like to qualify my objects. If this doesn't help, it's time to share more details. What is txtPeriodFrom? Is the calendar control part of the same userform? access user wrote: in my code please ignore the first section as it is headed with ' (I was just trying that out). So the code I am using and that does not work is: Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") tia James "access user" wrote: Hi Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson -- Dave Peterson |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
Thanks - that works - but how about if I want three dates? So when the focus is on the date1 textbox and I click the calendar, I want the date put in that box, when it is on date2 textbox.....etc I am guessing I would need to change the "Label1.Caption= " to a variable which changes value according to whichever box is in focus? can you help with that? tia James "Patrick Molloy" wrote: assuming that the objects are on teh same form, then you don't really need ther "me" thing Private Sub Calendar1_Click() Label1.Caption = Format$(Calendar1.Value, "ddd mm yyyy") End Sub "access user" wrote: in my code please ignore the first section as it is headed with ' (I was just trying that out). So the code I am using and that does not work is: Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") tia James "access user" wrote: Hi Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
Yes the three text boxes for the dates are on the same form as the calendar. Your code below works. However, I think you replied just as I posed my additional question. So now, if I want the date to go into whichever box has currently got the focus then how would you do that? tia James "Dave Peterson" wrote: Is txtPeriodFrom a textbox on that same form? Me.txtPeriodFrom.Value = Format(Calendar1.Value, "mmmm dd, yyyy") I still like to qualify my objects. If this doesn't help, it's time to share more details. What is txtPeriodFrom? Is the calendar control part of the same userform? access user wrote: in my code please ignore the first section as it is headed with ' (I was just trying that out). So the code I am using and that does not work is: Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") tia James "access user" wrote: Hi Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson -- Dave Peterson |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Won't the calendar control have focus?
But maybe you could keep track of which textbox you were in last: Option Explicit Dim LastTextBox As MSForms.TextBox Private Sub TextBox1_Enter() Set LastTextBox = Me.TextBox1 End Sub Private Sub TextBox2_Enter() Set LastTextBox = Me.TextBox2 End Sub Private Sub TextBox3_Enter() Set LastTextBox = Me.TextBox3 End Sub ===== Then in whatever procedure you're getting the dates... lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") But it would probably be better to check to see if there is a lasttextbox before you ask for the date: If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? end if access user wrote: Hi Yes the three text boxes for the dates are on the same form as the calendar. Your code below works. However, I think you replied just as I posed my additional question. So now, if I want the date to go into whichever box has currently got the focus then how would you do that? tia James "Dave Peterson" wrote: Is txtPeriodFrom a textbox on that same form? Me.txtPeriodFrom.Value = Format(Calendar1.Value, "mmmm dd, yyyy") I still like to qualify my objects. If this doesn't help, it's time to share more details. What is txtPeriodFrom? Is the calendar control part of the same userform? access user wrote: in my code please ignore the first section as it is headed with ' (I was just trying that out). So the code I am using and that does not work is: Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") tia James "access user" wrote: Hi Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ok - now I get the following error
error 91 Object variable or With block variable not set tia James "Dave Peterson" wrote: Won't the calendar control have focus? But maybe you could keep track of which textbox you were in last: Option Explicit Dim LastTextBox As MSForms.TextBox Private Sub TextBox1_Enter() Set LastTextBox = Me.TextBox1 End Sub Private Sub TextBox2_Enter() Set LastTextBox = Me.TextBox2 End Sub Private Sub TextBox3_Enter() Set LastTextBox = Me.TextBox3 End Sub ===== Then in whatever procedure you're getting the dates... lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") But it would probably be better to check to see if there is a lasttextbox before you ask for the date: If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? end if access user wrote: Hi Yes the three text boxes for the dates are on the same form as the calendar. Your code below works. However, I think you replied just as I posed my additional question. So now, if I want the date to go into whichever box has currently got the focus then how would you do that? tia James "Dave Peterson" wrote: Is txtPeriodFrom a textbox on that same form? Me.txtPeriodFrom.Value = Format(Calendar1.Value, "mmmm dd, yyyy") I still like to qualify my objects. If this doesn't help, it's time to share more details. What is txtPeriodFrom? Is the calendar control part of the same userform? access user wrote: in my code please ignore the first section as it is headed with ' (I was just trying that out). So the code I am using and that does not work is: Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") tia James "access user" wrote: Hi Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On what line?
Remember that if you never entered a textbox--or didn't change your code to keep track, then lasttextbox would be nothing. If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? else lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") end if access user wrote: Ok - now I get the following error error 91 Object variable or With block variable not set tia James "Dave Peterson" wrote: Won't the calendar control have focus? But maybe you could keep track of which textbox you were in last: Option Explicit Dim LastTextBox As MSForms.TextBox Private Sub TextBox1_Enter() Set LastTextBox = Me.TextBox1 End Sub Private Sub TextBox2_Enter() Set LastTextBox = Me.TextBox2 End Sub Private Sub TextBox3_Enter() Set LastTextBox = Me.TextBox3 End Sub ===== Then in whatever procedure you're getting the dates... lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") But it would probably be better to check to see if there is a lasttextbox before you ask for the date: If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? end if access user wrote: Hi Yes the three text boxes for the dates are on the same form as the calendar. Your code below works. However, I think you replied just as I posed my additional question. So now, if I want the date to go into whichever box has currently got the focus then how would you do that? tia James "Dave Peterson" wrote: Is txtPeriodFrom a textbox on that same form? Me.txtPeriodFrom.Value = Format(Calendar1.Value, "mmmm dd, yyyy") I still like to qualify my objects. If this doesn't help, it's time to share more details. What is txtPeriodFrom? Is the calendar control part of the same userform? access user wrote: in my code please ignore the first section as it is headed with ' (I was just trying that out). So the code I am using and that does not work is: Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") tia James "access user" wrote: Hi Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#12
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On the line
lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") Anyway, I have now incorporated your check to see if a box was selected, however, even when I select a box I always get the error prompt "select a textbox first". Isn't the problem that as soon as the calendar is clicked the focus from the textbox is lost? Would it help if the calendar was on its own separate form? ie - not on the same form as the textboxes? For completeness below is the full code as I have it now: Option Explicit Dim LastTextBox As MSForms.TextBox (above is under General Declarations) ___________________________________ Private Sub TextBox1_Enter() Set LastTextBox = Me.txtPeriodTo End Sub (above is under General) __________________________________ Private Sub TextBox2_Enter() Set LastTextBox = Me.txtPeriodFrom End Sub (above is under General) ___________________________________ Private Sub TextBox3_Enter() Set LastTextBox = Me.txtDate End Sub (above is under General) ____________________________________ Private Sub Calendar1_Click() If LastTextBox Is Nothing Then MsgBox "Select a textbox first!" 'Exit Sub 'or something???? Else LastTextBox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") End If End Sub (above block is under Calendar1 Click event) _________________________________ "Dave Peterson" wrote: On what line? Remember that if you never entered a textbox--or didn't change your code to keep track, then lasttextbox would be nothing. If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? else lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") end if access user wrote: Ok - now I get the following error error 91 Object variable or With block variable not set tia James "Dave Peterson" wrote: Won't the calendar control have focus? But maybe you could keep track of which textbox you were in last: Option Explicit Dim LastTextBox As MSForms.TextBox Private Sub TextBox1_Enter() Set LastTextBox = Me.TextBox1 End Sub Private Sub TextBox2_Enter() Set LastTextBox = Me.TextBox2 End Sub Private Sub TextBox3_Enter() Set LastTextBox = Me.TextBox3 End Sub ===== Then in whatever procedure you're getting the dates... lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") But it would probably be better to check to see if there is a lasttextbox before you ask for the date: If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? end if access user wrote: Hi Yes the three text boxes for the dates are on the same form as the calendar. Your code below works. However, I think you replied just as I posed my additional question. So now, if I want the date to go into whichever box has currently got the focus then how would you do that? tia James "Dave Peterson" wrote: Is txtPeriodFrom a textbox on that same form? Me.txtPeriodFrom.Value = Format(Calendar1.Value, "mmmm dd, yyyy") I still like to qualify my objects. If this doesn't help, it's time to share more details. What is txtPeriodFrom? Is the calendar control part of the same userform? access user wrote: in my code please ignore the first section as it is headed with ' (I was just trying that out). So the code I am using and that does not work is: Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") tia James "access user" wrote: Hi Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#13
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The events will be based on the name of the textboxes.
You'll need to make changes like this: Private Sub txtPeriodTo_Enter() Set LastTextBox = Me.txtPeriodTo End Sub For all of the textboxes. access user wrote: On the line lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") Anyway, I have now incorporated your check to see if a box was selected, however, even when I select a box I always get the error prompt "select a textbox first". Isn't the problem that as soon as the calendar is clicked the focus from the textbox is lost? Would it help if the calendar was on its own separate form? ie - not on the same form as the textboxes? For completeness below is the full code as I have it now: Option Explicit Dim LastTextBox As MSForms.TextBox (above is under General Declarations) ___________________________________ Private Sub TextBox1_Enter() Set LastTextBox = Me.txtPeriodTo End Sub (above is under General) __________________________________ Private Sub TextBox2_Enter() Set LastTextBox = Me.txtPeriodFrom End Sub (above is under General) ___________________________________ Private Sub TextBox3_Enter() Set LastTextBox = Me.txtDate End Sub (above is under General) ____________________________________ Private Sub Calendar1_Click() If LastTextBox Is Nothing Then MsgBox "Select a textbox first!" 'Exit Sub 'or something???? Else LastTextBox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") End If End Sub (above block is under Calendar1 Click event) _________________________________ "Dave Peterson" wrote: On what line? Remember that if you never entered a textbox--or didn't change your code to keep track, then lasttextbox would be nothing. If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? else lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") end if access user wrote: Ok - now I get the following error error 91 Object variable or With block variable not set tia James "Dave Peterson" wrote: Won't the calendar control have focus? But maybe you could keep track of which textbox you were in last: Option Explicit Dim LastTextBox As MSForms.TextBox Private Sub TextBox1_Enter() Set LastTextBox = Me.TextBox1 End Sub Private Sub TextBox2_Enter() Set LastTextBox = Me.TextBox2 End Sub Private Sub TextBox3_Enter() Set LastTextBox = Me.TextBox3 End Sub ===== Then in whatever procedure you're getting the dates... lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") But it would probably be better to check to see if there is a lasttextbox before you ask for the date: If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? end if access user wrote: Hi Yes the three text boxes for the dates are on the same form as the calendar. Your code below works. However, I think you replied just as I posed my additional question. So now, if I want the date to go into whichever box has currently got the focus then how would you do that? tia James "Dave Peterson" wrote: Is txtPeriodFrom a textbox on that same form? Me.txtPeriodFrom.Value = Format(Calendar1.Value, "mmmm dd, yyyy") I still like to qualify my objects. If this doesn't help, it's time to share more details. What is txtPeriodFrom? Is the calendar control part of the same userform? access user wrote: in my code please ignore the first section as it is headed with ' (I was just trying that out). So the code I am using and that does not work is: Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") tia James "access user" wrote: Hi Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#14
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Doh - of course! Sorry for being so silly. It all works now. Thanks very much
for your help. James "Dave Peterson" wrote: The events will be based on the name of the textboxes. You'll need to make changes like this: Private Sub txtPeriodTo_Enter() Set LastTextBox = Me.txtPeriodTo End Sub For all of the textboxes. access user wrote: On the line lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") Anyway, I have now incorporated your check to see if a box was selected, however, even when I select a box I always get the error prompt "select a textbox first". Isn't the problem that as soon as the calendar is clicked the focus from the textbox is lost? Would it help if the calendar was on its own separate form? ie - not on the same form as the textboxes? For completeness below is the full code as I have it now: Option Explicit Dim LastTextBox As MSForms.TextBox (above is under General Declarations) ___________________________________ Private Sub TextBox1_Enter() Set LastTextBox = Me.txtPeriodTo End Sub (above is under General) __________________________________ Private Sub TextBox2_Enter() Set LastTextBox = Me.txtPeriodFrom End Sub (above is under General) ___________________________________ Private Sub TextBox3_Enter() Set LastTextBox = Me.txtDate End Sub (above is under General) ____________________________________ Private Sub Calendar1_Click() If LastTextBox Is Nothing Then MsgBox "Select a textbox first!" 'Exit Sub 'or something???? Else LastTextBox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") End If End Sub (above block is under Calendar1 Click event) _________________________________ "Dave Peterson" wrote: On what line? Remember that if you never entered a textbox--or didn't change your code to keep track, then lasttextbox would be nothing. If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? else lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") end if access user wrote: Ok - now I get the following error error 91 Object variable or With block variable not set tia James "Dave Peterson" wrote: Won't the calendar control have focus? But maybe you could keep track of which textbox you were in last: Option Explicit Dim LastTextBox As MSForms.TextBox Private Sub TextBox1_Enter() Set LastTextBox = Me.TextBox1 End Sub Private Sub TextBox2_Enter() Set LastTextBox = Me.TextBox2 End Sub Private Sub TextBox3_Enter() Set LastTextBox = Me.TextBox3 End Sub ===== Then in whatever procedure you're getting the dates... lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") But it would probably be better to check to see if there is a lasttextbox before you ask for the date: If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? end if access user wrote: Hi Yes the three text boxes for the dates are on the same form as the calendar. Your code below works. However, I think you replied just as I posed my additional question. So now, if I want the date to go into whichever box has currently got the focus then how would you do that? tia James "Dave Peterson" wrote: Is txtPeriodFrom a textbox on that same form? Me.txtPeriodFrom.Value = Format(Calendar1.Value, "mmmm dd, yyyy") I still like to qualify my objects. If this doesn't help, it's time to share more details. What is txtPeriodFrom? Is the calendar control part of the same userform? access user wrote: in my code please ignore the first section as it is headed with ' (I was just trying that out). So the code I am using and that does not work is: Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") tia James "access user" wrote: Hi Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#15
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I don't like typing these event procedure names. I figure that all I can do is
screw them up. Instead, I use the topleft dropdown choose the correct control/category and the topright dropdown to choose the correct event. access user wrote: Doh - of course! Sorry for being so silly. It all works now. Thanks very much for your help. James "Dave Peterson" wrote: The events will be based on the name of the textboxes. You'll need to make changes like this: Private Sub txtPeriodTo_Enter() Set LastTextBox = Me.txtPeriodTo End Sub For all of the textboxes. access user wrote: On the line lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") Anyway, I have now incorporated your check to see if a box was selected, however, even when I select a box I always get the error prompt "select a textbox first". Isn't the problem that as soon as the calendar is clicked the focus from the textbox is lost? Would it help if the calendar was on its own separate form? ie - not on the same form as the textboxes? For completeness below is the full code as I have it now: Option Explicit Dim LastTextBox As MSForms.TextBox (above is under General Declarations) ___________________________________ Private Sub TextBox1_Enter() Set LastTextBox = Me.txtPeriodTo End Sub (above is under General) __________________________________ Private Sub TextBox2_Enter() Set LastTextBox = Me.txtPeriodFrom End Sub (above is under General) ___________________________________ Private Sub TextBox3_Enter() Set LastTextBox = Me.txtDate End Sub (above is under General) ____________________________________ Private Sub Calendar1_Click() If LastTextBox Is Nothing Then MsgBox "Select a textbox first!" 'Exit Sub 'or something???? Else LastTextBox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") End If End Sub (above block is under Calendar1 Click event) _________________________________ "Dave Peterson" wrote: On what line? Remember that if you never entered a textbox--or didn't change your code to keep track, then lasttextbox would be nothing. If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? else lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") end if access user wrote: Ok - now I get the following error error 91 Object variable or With block variable not set tia James "Dave Peterson" wrote: Won't the calendar control have focus? But maybe you could keep track of which textbox you were in last: Option Explicit Dim LastTextBox As MSForms.TextBox Private Sub TextBox1_Enter() Set LastTextBox = Me.TextBox1 End Sub Private Sub TextBox2_Enter() Set LastTextBox = Me.TextBox2 End Sub Private Sub TextBox3_Enter() Set LastTextBox = Me.TextBox3 End Sub ===== Then in whatever procedure you're getting the dates... lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") But it would probably be better to check to see if there is a lasttextbox before you ask for the date: If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? end if access user wrote: Hi Yes the three text boxes for the dates are on the same form as the calendar. Your code below works. However, I think you replied just as I posed my additional question. So now, if I want the date to go into whichever box has currently got the focus then how would you do that? tia James "Dave Peterson" wrote: Is txtPeriodFrom a textbox on that same form? Me.txtPeriodFrom.Value = Format(Calendar1.Value, "mmmm dd, yyyy") I still like to qualify my objects. If this doesn't help, it's time to share more details. What is txtPeriodFrom? Is the calendar control part of the same userform? access user wrote: in my code please ignore the first section as it is headed with ' (I was just trying that out). So the code I am using and that does not work is: Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") tia James "access user" wrote: Hi Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#16
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for that additional tip - makes more sense now.
James "Dave Peterson" wrote: I don't like typing these event procedure names. I figure that all I can do is screw them up. Instead, I use the topleft dropdown choose the correct control/category and the topright dropdown to choose the correct event. access user wrote: Doh - of course! Sorry for being so silly. It all works now. Thanks very much for your help. James "Dave Peterson" wrote: The events will be based on the name of the textboxes. You'll need to make changes like this: Private Sub txtPeriodTo_Enter() Set LastTextBox = Me.txtPeriodTo End Sub For all of the textboxes. access user wrote: On the line lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") Anyway, I have now incorporated your check to see if a box was selected, however, even when I select a box I always get the error prompt "select a textbox first". Isn't the problem that as soon as the calendar is clicked the focus from the textbox is lost? Would it help if the calendar was on its own separate form? ie - not on the same form as the textboxes? For completeness below is the full code as I have it now: Option Explicit Dim LastTextBox As MSForms.TextBox (above is under General Declarations) ___________________________________ Private Sub TextBox1_Enter() Set LastTextBox = Me.txtPeriodTo End Sub (above is under General) __________________________________ Private Sub TextBox2_Enter() Set LastTextBox = Me.txtPeriodFrom End Sub (above is under General) ___________________________________ Private Sub TextBox3_Enter() Set LastTextBox = Me.txtDate End Sub (above is under General) ____________________________________ Private Sub Calendar1_Click() If LastTextBox Is Nothing Then MsgBox "Select a textbox first!" 'Exit Sub 'or something???? Else LastTextBox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") End If End Sub (above block is under Calendar1 Click event) _________________________________ "Dave Peterson" wrote: On what line? Remember that if you never entered a textbox--or didn't change your code to keep track, then lasttextbox would be nothing. If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? else lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") end if access user wrote: Ok - now I get the following error error 91 Object variable or With block variable not set tia James "Dave Peterson" wrote: Won't the calendar control have focus? But maybe you could keep track of which textbox you were in last: Option Explicit Dim LastTextBox As MSForms.TextBox Private Sub TextBox1_Enter() Set LastTextBox = Me.TextBox1 End Sub Private Sub TextBox2_Enter() Set LastTextBox = Me.TextBox2 End Sub Private Sub TextBox3_Enter() Set LastTextBox = Me.TextBox3 End Sub ===== Then in whatever procedure you're getting the dates... lasttextbox.Value = Format(Calendar1.Value, "mmmm dd, yyyy") But it would probably be better to check to see if there is a lasttextbox before you ask for the date: If LastTextBox Is Nothing Then MsgBox "Select a textbox first! exit sub 'or something???? end if access user wrote: Hi Yes the three text boxes for the dates are on the same form as the calendar. Your code below works. However, I think you replied just as I posed my additional question. So now, if I want the date to go into whichever box has currently got the focus then how would you do that? tia James "Dave Peterson" wrote: Is txtPeriodFrom a textbox on that same form? Me.txtPeriodFrom.Value = Format(Calendar1.Value, "mmmm dd, yyyy") I still like to qualify my objects. If this doesn't help, it's time to share more details. What is txtPeriodFrom? Is the calendar control part of the same userform? access user wrote: in my code please ignore the first section as it is headed with ' (I was just trying that out). So the code I am using and that does not work is: Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") tia James "access user" wrote: Hi Thanks for your response, however it does not work. I have the following code: Private Sub EnterDate() 'Me.txtPeriodFrom.ControlSource = Worksheets("InputDataEntry").Range("A1").Value Me.txtPeriodFrom.ControlSource = Format(Calendar1.Value, "mmmm dd, yyyy") End Sub Where I have "ControlSource" is where you had "caption" in your suggestion. Caption was not recognised. Any other suggestions? tia James "Dave Peterson" wrote: Maybe something like: Me.label1.caption = format(calendar1.value,"mmmm dd, yyyy") access user wrote: Hi I have followed the link that RondeBruin gives to this site http://www.fontstuff.com/vba/vbatut07.htm which shows how to add a calendar control. However I want to pass the date from the calendar to a field on a form (the calendar and field in question are both on the same form). The info on the above link only shows how to pass it to an active cell on the worksheet. Would appreciate any help. tia James -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Calendar pop-up on a date field?? | Excel Discussion (Misc queries) | |||
add a calendar control in Excel form | Excel Programming | |||
Copy form field value to another form (calendar) | Excel Programming | |||
Updating Page Field of Pivot Tables from Form Control | Excel Discussion (Misc queries) | |||
calendar/date control | Excel Programming |