View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
access user access user is offline
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