Selecting Date from Calendar to text box

G

Guest

I have a text box named "Date", with control source "Assigned Date1" which is
the field in the access table it will populate. I have a calendar named
"Calendar1". Visible is set to No. I wish to click on text box - have
calendar appear - click date to populate in text box and have calendar
disappear. I have the following codes for calendar and text box.
Private Sub Calendar1_Click()
'Setdate written to the selected date and hide the calendar.
'MsgBox(ctrname)
'Dt_written.Value = Calendar1.Value
'Dt_written.SetFocus
'msgbox(currtl)
currctl.Value = Calendar1.Value
currctl.SetFocus
Calendar1.Visible = False
Set currctl = Nothing
End Sub


Private Sub Date_MouseDown(Button As Integer, Shift As Integer, X As Single,
Y As Single)
'show Calendar1
'Dim currctl As Control, ctrname As String
Set currctl = Screen.ActiveControl
ctrname = currctl.Name
Calendar1.Value = currctl.Value
Calendar1.Visible = True
End Sub
When I click on text box, calendar appears but when I click on date I get an
error
I would greatly appreciate assistance with this.
Thank you - Ken
 
R

Regan via AccessMonster.com

Ken said:
I have a text box named "Date", with control source "Assigned Date1" which is
the field in the access table it will populate. I have a calendar named
"Calendar1". Visible is set to No. I wish to click on text box - have
calendar appear - click date to populate in text box and have calendar
disappear. I have the following codes for calendar and text box.
Private Sub Calendar1_Click()
'Setdate written to the selected date and hide the calendar.
'MsgBox(ctrname)
'Dt_written.Value = Calendar1.Value
'Dt_written.SetFocus
'msgbox(currtl)
currctl.Value = Calendar1.Value
currctl.SetFocus
Calendar1.Visible = False
Set currctl = Nothing
End Sub

i think you would have to Dim Currctl again

Set currctl = Screen.ActiveControl
ctrname = currctl.Name

maybe, thou not sure

try this

Private Sub Calendar1_click()

forms!Formname![Date] = calendar1.value
Calendar1.visible = false

end sub
Works for me

Shouldn't use Date as a textbox name thou, it's a reserved work, something
like txtstartDate would be better.

hope this helps a little

--
Regan,
Paeroa
World famous in New Zealand

Message posted via AccessMonster.com
 
M

missinglinq via AccessMonster.com

Not only is Date a Reserved word, it's actually a Statement in Access!

Date = calenda1.Value

doesn't assign the calendar1 value to your textbox, it sets your PC's system
clock to this date!

In a similar fashion

Time = "12:001 PM" would set you system's clock to 12:01 PM!

So after changing the name of your textbox, as has already been suggested,
you might want to check your system's clock to make sure it's set correctly!


Good Luck!

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
G

Guest

Thank you all very much for your help. As you can tell I am still new at
this. I changed the name as suggested which makes perfect sense and have
made this work now. Thank you again, I really appreciate it!!
Ken

Regan via AccessMonster.com said:
Ken said:
I have a text box named "Date", with control source "Assigned Date1" which is
the field in the access table it will populate. I have a calendar named
"Calendar1". Visible is set to No. I wish to click on text box - have
calendar appear - click date to populate in text box and have calendar
disappear. I have the following codes for calendar and text box.
Private Sub Calendar1_Click()
'Setdate written to the selected date and hide the calendar.
'MsgBox(ctrname)
'Dt_written.Value = Calendar1.Value
'Dt_written.SetFocus
'msgbox(currtl)
currctl.Value = Calendar1.Value
currctl.SetFocus
Calendar1.Visible = False
Set currctl = Nothing
End Sub

i think you would have to Dim Currctl again

Set currctl = Screen.ActiveControl
ctrname = currctl.Name

maybe, thou not sure

try this

Private Sub Calendar1_click()

forms!Formname![Date] = calendar1.value
Calendar1.visible = false

end sub
Works for me

Shouldn't use Date as a textbox name thou, it's a reserved work, something
like txtstartDate would be better.

hope this helps a little

--
Regan,
Paeroa
World famous in New Zealand

Message posted via AccessMonster.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top