Keeping Form Maximized

S

Sprinks

From a maximized form, a button opens a 2nd form which is maximized in its
OnOpen event. When it is closed, the first form is no longer maximized, with
the database window visible beneath.

Adding a DoCmd.Maximize works in the OnActivate event procedure, however,
the DB window is still briefly visible.

Can anyone tell me how to return to the maximized form?

Thank you.
Sprinks
 
S

Steve Schapel

Sprinks,

If the first form is maximized, I would expect that the 2nd form would
automatically be maximized too, without you needing to explicitly do so
in its Open event. This makes me wonder whether there is a Restore
method used somewhere in the process?
 
S

Sprinks

Steve,

Thank you for your response.

No; there is no Restore code anywhere. I have posted the code for both
forms below. They are part of a Timesheet database. The application uses
dummy, non-normalized tables for the entry form because they allow more
convenient data entry--the user cursors between date columns in a
spreadsheet-like form. When each user has entered the 2-week period, the
data is posted to normalized tables, and the dummy tables reset to the next
period.

The ResetLabels and UpdateTotals procedures are used to update totals rather
than using calculated controls because I found them to produce less delay and
screen flicker on each entry.

Perhaps you can find my errant way.

Thank you.
Sprinks


‘ Form 1 Code (Timesheet Entry form)
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Handler
Dim intI As Integer
Dim intDay As Integer
Dim dteStartDate As Date
Dim ctl As Control

‘ TSQueryAll used when management is reviewing all open timesheets
‘ Otherwise, the Timesheet opens to the CurrentUser()’s record
If Me.OpenArgs = "TSQueryAll" Then
dteStartDate = DMax("[PeriodBeginning]", "TSHistory")
With Me
.RecordSource = Me.OpenArgs
.AllowAdditions = True
.AllowDeletions = True
.AllowEdits = True
.Controls("cboStaffName").Visible = True
.Controls("cboStaffName").SetFocus
.Controls("txtStaffName").Visible = False
.Controls("cboPeriodStartDate").Visible = True
.Controls("txtPeriodStartDate").Visible = False
.Controls("cboPeriodStartDate").RowSource = dteStartDate - 14 &
";" & dteStartDate & ";" _
& dteStartDate + 14 & ";" & dteStartDate + 28
.Controls("cboPeriodStartDate").Requery
.Controls("cmdPost").Visible = False
.Visible = True
End With

Else

With Forms("Timesheet").Controls("TimeSheetDetail")
.SetFocus
If Not IsNull(.Form![cboProjectNumber]) Then
intDay = 0

' Determine first day of less than 8 hours
For intI = 3 To 7
If Forms("Timesheet").Controls("txtSumofDay" &
Trim(Str(intI))) < 8 Then
intDay = intI
Exit For
End If
Next intI

If intDay = 0 Then

' We found the first non-zero day, so skip this code
For intI = 10 To 14
If Forms("Timesheet").Controls("txtSumofDay" &
Trim(Str(intI))) < 8 Then
intDay = intI
Exit For
Else
intDay = 1
End If
Next intI

End If
.Form.Controls("txtHours" & Trim(Str(intDay))).SetFocus
Else
.Form![cboProjectNumber].SetFocus
End If

End With

End If

' Reset Labels & initialize totals
Call ResetLabels
Call UpdateTotals

Err_Exit:
Exit Sub

Err_Handler:
Select Case Err.Number
Case 2105, 2110 ' Can't set focus to txtHours1
Resume Next

Case 2455 ' No Timesheet record exists
MsgBox "A timesheet has not yet been initialized for you." &
vbCrLf & _
"Please see the Office Manager or system
administrator.", vbOKOnly, _
"Missing Timesheet Record"
DoCmd.Close
Case Else
MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & vbCrLf & _
"Please contact the system administrator with the above
information.", vbOKOnly, _
"Runtime Error"
End Select
Resume Err_Exit

End Sub

Private Sub Form_Activate()
On Error Resume Next
Me.Visible = False
DoCmd.Maximize
Me.Visible = True
End Sub

Private Sub Form_Current()
On Error GoTo Err_Handler

Call ResetLabels
Call UpdateTotals

Err_Exit:
Exit Sub

Err_Handler:
Select Case Err.Number
Case 2110 ' Can't set focus to txtHours
Me![cboProjectNumber].SetFocus
Resume Next

Case Else
MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & vbCrLf & _
"Please contact the system administrator with the above
information.", vbOKOnly, _
"Runtime Error"
End Select
Resume Err_Exit

End Sub

Private Sub ResetLabels()
On Error GoTo Err_Handler

Dim ctl As Control
For Each ctl In Me![TimeSheetDetail].Form.Controls
If Left(ctl.name, 7) = "lblDate" Then
ctl.Caption = Format([PeriodStartDate] + Mid(ctl.name, 8) - 1,
"mm/dd")
End If
Next ctl

Err_Exit:
Exit Sub

Err_Handler:
MsgBox "The following error has occurred. Please contact the system
administrator." & _
vbCrLf & vbCrLf & Err.Number & vbCrLf & Err.Description, vbOKOnly,
"Runtime Error"
Resume Err_Exit

End Sub

Private Sub UpdateTotals()
On Error GoTo Err_Handler

Dim intParam As Integer
Me.Refresh

For intParam = 1 To 14
' Update day subtotals
Me![TimeSheetDetail].Form!("SumofDetailHours" & intParam) = _
Nz(DSum("[DayHours" & intParam & "]", _
"TSDetailQry", "[TimesheetID] = " & Me![TimesheetID]))

Me![TimeSheetAdminDetail].Form!("SumofAdmin" & intParam) = _
Nz(DSum("[DayHours" & intParam & "]", _
"TSAdminDetailQry", "[TimesheetID] = " & Me![TimesheetID]))

' Update day totals
Me("txtSumofDay" & intParam) = _
Nz(Me![TimeSheetDetail].Form!("SumofDetailHours" &
intParam)) + _
Nz(Me![TimeSheetAdminDetail].Form!("SumofAdmin" & intParam))

Next intParam

' Update sum of row subtotals
Me![TimeSheetDetail].Form![txtSumofSumDetail] = _
Nz(DSum("[RT]", "TSDetailQry", "[TimesheetID] = " &
Me![TimesheetID]))

Me![TimeSheetAdminDetail].Form![txtSumofSumAdmin] = _
Nz(DSum("[RT]", "TSAdminDetailQry", "[TimesheetID] = " &
Me![TimesheetID]))

' Update grand total
Me![txtGrandTotal] = Nz(Me![TimeSheetDetail]![txtSumofSumDetail]) + _

Nz(Me![TimeSheetAdminDetail].Form![txtSumofSumAdmin])


Err_Exit:
Exit Sub

Err_Handler:
Select Case Err.Number
Case 3075
Resume Next
Case Else
MsgBox "The following error has occurred. Please contact the
system administrator." & _
vbCrLf & vbCrLf & Err.Number & vbCrLf & Err.Description,
vbOKOnly, "Runtime Error"
Resume Err_Exit
End Select


End Sub

Private Sub cmdOldTS_Click()
DoCmd.OpenForm "TimeRecordsByStaff", acNormal, , _
"StaffID = " & Me![txtStaffID], acFormReadOnly, acWindowNormal,
"Review"
End Sub


‘ Code for Form 2, opened by cmdOldTS_Click()
‘ Used by user to review his previous time records
‘ The same form is used by management, unfiltered by StaffID to review all
‘ historical records
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Handler

DoCmd.Maximize
Me.Visible = True

Err_Exit:
Exit Sub

Err_Handler:
MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & vbCrLf & _
"Please contact the system administrator with the above
information.", vbOKOnly, _
"Runtime Error"
GoTo Err_Exit

End Sub
Private Sub Form_Activate()
On Error Resume Next

Me![txtPeriodEnding].SetFocus

End Sub

Private Sub Form_Current()
On Error GoTo Err_Handler

Me![TRDates_Staff].Requery

Err_Exit:
Exit Sub

Err_Handler:
Select Case Err.Number
Case Else
MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & vbCrLf & _
"Please contact the system administrator with the above
information.", vbOKOnly, _
"Runtime Error"
End Select
GoTo Err_Exit

End Sub
 

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

Similar Threads

Forms Not Staying Maximized 1
Form Appearance 0
Startup display form always maximized 3
Maximizing Forms 0
Form events 1
Center content in maximized form 1
open form NOT maximized 2
Can't keep form maximized 2

Top