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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveX Closing my Form

Status
Not open for further replies.

LarryDeLaruelle

Technical User
May 19, 2000
1,055
US
I'm using the ActiveX Calendar control to allow my users to select a beginning report date. Based on that date, I want to set the ending date (usually first to last of month).

I'm still new to ActiveX and I'm not sure how they work. I picked up the code for this from a book and am trying to modify it for my needs.

I tried putting the date manipulation code at the end of the procedure that calls the calendar but it treats the date as it was originally set (on open = Date(); if I leave it empty, I get a Type Mismatch [null?] error when I call frmCalendar). Yet, when frmCalendar closes the date displayed correctly in by text box.

I put the date manipulation code in the txtStart After Update event -- Nothing happens even though the date is updated.

I then tried putting a txtStart.SetFocus at the end of the code which calls frmCalendar and the date manipulation code in the On Got Focus event, guess what? The Set Focus closes my calling form. I'm stumped! Here is the code calling frmCalendar:

Dim frmCal As Form
Dim ctlD As Control
Dim datToday As Date

Set ctlD = Me!txtStart
DoCmd.OpenForm "frmCalendar", , , , , acHidden
Set frmCal = Forms("frmCalendar")
With frmCal
Set .DateControl = ctlD
.InitialDate = ctlD.Value
.Visible = True
End With

Here is the code from frmCalendar:

Option Compare Database
Option Explicit

Private mctlDate As Control

Public Property Set DateControl(ByVal ctlDate As Control)

Set mctlDate = ctlDate

End Property

Public Property Let InitialDate(datD As Date)

Me!ctlCalendar = datD

End Property

Private Sub SetAndClose()

If mctlDate Is Nothing Then
MsgBox "The Date has not been set", , "Calendar Form Error"
Else
mctlDate = ctlCalendar.Value
End If

DoCmd.Close

End Sub

Private Sub ctlCalendar_Click()

SetAndClose

End Sub
Private Sub ctlCalendar_KeyUp(KeyCode As Integer, ByVal Shift As Integer)

Select Case KeyCode
Case vbKeyReturn
SetAndClose
Case vbKeyEscape
DoCmd.Close
End Select

End Sub
Private Sub ctlCalendar_updated(code As Integer)

End Sub

How can I call the calendar and then execute my date commands?

Any help will be appreciated.

Thanks.
Larry De Laruelle
larry1de@yahoo.com

 
The ActiveX is inserting to txtStart Ok right? If so force the focus to fall on txtStart after the insert or close of the Calendar. If it doesn't muddle up your records integrity, In its On Got Focus event add:
DoCmd.RunCommand acCmdSaveRecord
Me.[NameOfEndDate]=Me.txtStart+10
(This is just a test to see if we're going the right direction.)
Gord
ghubbell@total.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top