Behaviour depends on the placement of DoCmd Close, acform...

S

SlowArrow

Dear Form Gurus,

I've made a popup, modal dialog form in MS Access 2003 holding just an
MSCAL.OCX type Calendar control. I'm calling it from the MouseDown events of
some comboboxes of a non-modal sizable form. In the caller event I open the
form with the DoCmd.Open as a dialog form, and pass the value of the actual
date of the combobox together with the actual mouse position to the
Calendar-form. Clicking a date of the calendar control I dont close its form,
however i hide it, and I get back the selected date by the code in the caller
event. Then I close the Calendar-form.
However, this does not work correctly, if i use 2 comboboxes, the openarg
contains nothing. If i place do closing just before the opening of the
Calendar-form, then it works well. I would appreciate, if you explain this?

All the related code is below.

Thanks, ahead:)

SlowArrow

The caller form's codes:

Private Sub START_DATE_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
SetDate Me.START_DATE, X
End Sub


Private Sub END_DATE_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
SetDate Me.END_DATE, X
End Sub


Private Sub SetDate(ByRef cmbDate As ComboBox, X As Single)
Dim ResultFlag As Integer, hTitle As Integer, myDate As Date, strArgs As
String
hTitle = GetSystemMetrics(SM_CYSIZE) ' height of a button
in a window caption or title bar
If X > cmbDate.Width - 15 * 20 Then
If cmbDate.ListCount > 0 Then cmbDate.RemoveItem 0
cmbDate.AddItem cmbDate.Value
SendKeys "^{UP}{ESCAPE}"
Else
myDate = cmbDate.Value
strArgs = cmbDate.Text & "|" & CStr(Me.WindowTop + cmbDate.Top +
cmbDate.Height + hTitle * 20) & _
"|" & CStr(Me.WindowLeft + cmbDate.Left +
cmbDate.Width - Form_Calendar.Width) & "|" & cmbDate.Name
' Debug.Print "Form_Call: """ & strArgs & """ - " & CStr(ixCount)
' On Error Resume Next
DoCmd.Close acForm, CalendarDialog
DoCmd.OpenForm CalendarDialog, , , , , acDialog, strArgs
ResultFlag = Forms(CalendarDialog).Form.Tag
If ResultFlag = vbOK Then myDate =
Forms(CalendarDialog)!ocxCalendar.Value
' DoCmd.Close acForm, CalendarDialog
cmbDate.Value = myDate
End If
cmbDate.SetFocus
End Sub


The Calendar-form's codes:

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Dim MyArray() As String
MyArray = Split(Me.OpenArgs, "|")
Me.ocxCalendar.Value = CDate(MyArray(0))
Me.Move Left:=Int(MyArray(2)), Top:=Int(MyArray(1))
' Debug.Print "Form_Load: """ & Me.OpenArgs & """ - " & CStr(ixCount)
' ixCount = ixCount + 1
End If
End Sub

Public Sub ocxCalendar_Click()
Me.Visible = False
Me.Tag = vbOK
End Sub
 
S

SlowArrow

I want to explain a bit better the situation in the wrong case (when I put do
DoCmd.Close ... statement for the CalendarDialog _following_ the line serving
for obtaining the selected date):

Immediately after opening the caller window I clicked on one of the Combo
boxes. The CalendarDialog form appears, as we expect it, and it is possible
to select a date by its MSCAL.OCX calendar control, by clicking a date. Then
this form disappears from the screen (because of setting the Visible property
to False in the control's click event). Then I clicked on the other combobox.
The calendar form appeared, _but in its previous place_, meaning that the
OpenArgs was null in the Form_Load event. The contents of the OpenArgs seems
to be correct at the time of the call. I've realised, that the Form_Load is
activated twice: at first with empty OpenArgs, and sometimes with its correct
value. I'm a bit confused about these. I would like to ask some expalnation
for this.
 
S

SlowArrow

I'm not impatient, just like to know, wether this is the correct forum for my
question, or should i post it under the Access.formscoding... besides the
answer for my original question:)
 

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