Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button of Calendar Entry 1

Status
Not open for further replies.

JockVSJock

Technical User
Jun 28, 2001
59
US

I've seen some examples on some forms where a person can click a button and the calendar appears and that person can select a date and it writes to whatever field/table.

Can anyone provide a simple example of how to code this thru VBA?

thanks

-Chris

 
Hi there
Which Version are you in if you are in 2000 the hammer an spanner icon on the toolbar displayed in form design offer you the Calendar object. As I have Vis Studio & VB they may be inherited from there but have a check and see

regards


jo
 
Example at the address below and some code from Bill Gates



SUMMARY
When you want to have a user enter a date value on a form, you can improve usability of the form by providing a Calendar control on the form. To reduce clutter on the form, you can simulate a feature of Microsoft Outlook by having the calendar pop up when the user clicks a button. This article describes how to create a pop-up calendar by using a combo box and the Calendar control (mscal.ocx).



MORE INFORMATION

Creating a Pop-Up Calendar
Open the sample database Northwind.mdb.


Create a new form based on the Orders table and save it as frmOrderDateForm.


Add a combo box to the form and set the ControlSource property of the combo box to the OrderDate field.


Insert the Calendar control on the form.

NOTE: To insert a Calendar control, click ActiveX Control on the Insert menu, and then select either Calendar Control or Calendar Control 8.0 depending on your version of Access, 7.0 or 97.


Set the following properties for the Calendar control:


Name: Calendar
Visible: No
Add the following code to the MouseDown event of the OrderDate combo box:


Private Sub OrderDate_MouseDown(Button As Integer, _
Shift As Integer, X As Single, _
Y As Single)
' Show Calendar and set its date.
Calendar.Visible = True
Calendar.SetFocus
' Set to today if OrderDate has no value.
Calendar.Value = IIf(IsNull(OrderDate), Date, OrderDate.Value)
End Sub
Add the following code to the Click event of the Calendar control.

NOTE: You will have to open up one of the listed events and then change that event to the Click event.


Private Sub Calendar_Click()
' Set OrderDate to the selected date and hide the calendar.
OrderDate.Value = Calendar.Value
OrderDate.SetFocus
Calendar.Visible = False
End Sub
Save the form and switch to Form View.


You will find that when you click the arrow in the OrderDate box, the Calendar control will be made visible and will be set to the date in the box. After you select a date from the calendar, the calendar will disappear and the selected date will now be in the box. If the OrderDate box has no value, the calendar will show the current date.
Additional Example
If you are using Access 97, you can see an additional example of using the Calendar control as well as other ActiveX controls in the Microsoft Access 97 ActiveX Control Samples database. The database is distributed on the Office 97 Developer Edition (ODE) CD in the following directory:
CD-DRIVE:\MSDS\ODESMPL\ODE\OLECONT\Actctrls.mdb
If you don't have the ODE, you can download this database from Microsoft's Support Web site at the following address:
Neil Berryman
IT Trainer
neil_berryman@btopenworld.com
 
When I attempt to place the Line "OrderDate.SetFocus, the command is showing a Value to enter. When I enter the listed code I get a Yellow Line showing me that the deo is not valid.


Please advise.



Thanks



Jack
 
Excellant solution. I am using MS Access and I don't have 'Click' event shown as part of the calander properties. I am sure you mean something when you say " NOTE: You will have to open up one of the listed events and then change that event to the Click event.:" but not too sure what is meant by this. Could you please exaplain this a little further?

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top