I have two problems that I cannot work out.
I have two user forms - the first 'frmCalendar' is opened after a new sheet is added to my workbook and the user then has to click a date to move on.
The click event works fine,and the date is entered into the sheet. However the form will not unload. (I can get it to hide, but once it has been used it is not required again in this process, therefore I want to unload it from memory)
I don't know why it will not unload, but it stays on the screen until the 'unload' code of the next form is activated via a command button click event.
Sub Calendar1_Click()
' Transfer date selected on calendar to active cell
' and close UserForm.
ActiveCell.Value = Calendar1.Value
ActiveCell.Offset(0, -2).Select
Unload frmCalendar
frmNewOrder.Show
End Sub
The second form which is opened from the click event of the calendar also has a problem in that I cannot get it to place at the precise point that I want, and I think it has something to do with the calendar, which also is placed precisely using the code below
Private Sub UserForm_Initialize()
With frmCalendar
.Top = Application.Top + 125 '< change 125 to what u want
.Left = Application.Left + 325 '< change 25 to what u want
End With
If IsDate(ActiveCell.Value) Then
Calendar1.Value = DateValue(ActiveCell.Value)
Else
Calendar1.Value = Date
End If
End Sub
and this is the NewOrder form code
Option Explicit
Private Sub UserForm_Initialize()
With frmNewOrder
.Top = Application.Top + 25 '< change 225 to what u want
.Left = Application.Left + 325 '< change 25 to what u want
End With
'initialises the order form so that it can capture the previous order no on the
'sheet to the left and then add one in the txtOrderNo box, and
'finally pass the new order No to the sheet
If ActiveSheet.Index > 6 Then
txtOrderNo.Value = Worksheets(ActiveSheet.Index - 1).Range("C16") + "1"
Else
txtOrderNo.Value = "1"
End If
End Sub
As can be seen the placement code is the same. It works for the calendar, but not for the new order form.
Hope someone can help -- its got me beat.
Bookmarks