Full Version: Date ActiveX + Forms
UtterAccess Discussion Forums > Microsoft® Access > Access Date + Time
Grafixx01
Ok, this is my issue. I am trying to have a form, already created, with a Calendar (I did that through the add Active X control). it works fine and all. The issue that I am having is:

1. Trying to put a command button on that frmCalendar so that when you click it, it will insert the current / selected date that you chose into a field on the form.

Any ideas?

Thanks in advance,

Bryan
fkegley
This is going to sound a bit crazy, but I just tried it and it works. Open the form in design view, then open the code window. Set the left dropdown to the calendar control, set the right dropdown to the Click event.

Then type:

Me.[NameOfTextBox] = Me.[NameOfCalendarControl]
Grafixx01
Ok, now here's the issue that I may have not said. I have a whole lot of these on the initial data entry form for the individuals (ie: date to XO, date from XO, date to CSM, etc.). I think there will be approximately 24 of these command buttons to open the frmCalendar, then select the date, then click the "insert selected date" command button on the frmCalendar to insert it into the specific area on the main form.

Did I confuse anyone?
fkegley
Yes, the way to do this would be to develop a separate form that contains the Calendar Control. You'll then need command buttons, or some other way, that will open the Calendar form and at the same time pass to the Calendar form the name of the text box that will receive the clicked date.

For instance, in the click event of a command button:

DoCmd.OpenForm "CalendarFormName",,,,,,Me.[NameOfTextBox]

Then in the Click event of the Calendar control:

Forms("FirstFormName").Controls(Me.OpenArgs) = Me.[CalendarControlName]
Grafixx01
Ok, I tried some things and the code is below. Now when I try to put the frmCalendar into datasheet view it comes up with an error on the last Sub of "compile error : sub or function not defined"

here is the code (it is the portion at the bottom that is in ITALICS):

Option Compare Database
Option Explicit 'delete if is doesn't work
Private strparentForm, strTextBox 'delete if it doesn't work



Private Sub Calendar0_Updated(Code As Integer)

End Sub

Private Sub Command2_Click()
Me.Visible = False 'delete if it doesn't work
Forms(strparentForm).Controls(strTextBox).SetFocus 'delete if it doesn't work
Forms(strparentForm).Controls(strTextBox).Text = CDate(calCalendar.Value) 'delete if it doesn't work
DoCmd.Close acForm, Me.Name, acSaveNo 'delete if it doesn't work
End Sub

Private Sub ExitCalendar_Click()
On Error GoTo Err_ExitCalendar_Click


DoCmd.Close acForm, Me.Name, acSaveNo 'delete if it doesn't work

Exit_ExitCalendar_Click:
Exit Sub

Err_ExitCalendar_Click:
MsgBox Err.Description
Resume Exit_ExitCalendar_Click

End Sub
Private Sub Form_Open(Cancel As Integer) 'delete if it doesn't work
Dim dtDate As Date 'delete if it doesn't work
strparentForm = GetParentForm(Me.OpenArgs) 'delete if it doesn't work
strTextBox = GetControlName(Me.OpenArgs) 'delete if it doesn't work
dtDate = GetDateDefault(Me.OpenArgs) 'delete if it doesn't work

calCalendar.SetFocus 'delete if it doesn't work
calCalendar.Value = dtDate 'delete if it doesn't work

End Sub 'delete if it doesn't work
Grafixx01
Frank,

I did what you said, I put the vb code in for the 'click event' on the main form 'cmdDCdate' button to read:

stDocName = "frmCalendar"
DoCmd.OpenForm stDocName, , , Me.cmdDCdate

When I did this, I tried to click it in 'form view' and it returned the following error message:

An expression you entered is the wrong data type for one of the arguments.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.