Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default How to Pass a date from a calendar control to a field on a form

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to Pass a date from a calendar control to a field on a form

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default How to Pass a date from a calendar control to a field on a for

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default How to Pass a date from a calendar control to a field on a for

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default How to Pass a date from a calendar control to a field on a for

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to Pass a date from a calendar control to a field on a for

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default How to Pass a date from a calendar control to a field on a for

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default How to Pass a date from a calendar control to a field on a for

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to Pass a date from a calendar control to a field on a for

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default How to Pass a date from a calendar control to a field on a for

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to Pass a date from a calendar control to a field on a for

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default How to Pass a date from a calendar control to a field on a for

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to Pass a date from a calendar control to a field on a for

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default How to Pass a date from a calendar control to a field on a for

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to Pass a date from a calendar control to a field on a for

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default How to Pass a date from a calendar control to a field on a for

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calendar pop-up on a date field?? stewarddj Excel Discussion (Misc queries) 1 March 11th 08 11:44 AM
add a calendar control in Excel form Bhirsch Excel Programming 1 October 23rd 07 07:28 PM
Copy form field value to another form (calendar) [email protected] Excel Programming 1 December 1st 05 09:58 PM
Updating Page Field of Pivot Tables from Form Control RestlessAde Excel Discussion (Misc queries) 1 August 3rd 05 09:00 PM
calendar/date control peter Excel Programming 1 June 9th 04 04:02 PM


All times are GMT +1. The time now is 06:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"