mcelligott
Programmer
I have an issue I have not run across before (probably because I do not use a lot of VBA). I have written some code to open (preview) some reports. However, the first time I try to preview any of the report (no matter which one), it comes up but gets hidden behind the switchboard (which is maximized). It only happens the first time a report from the list comes up. After that, the reports will preview without a problem. I have made sure the switchboard is not set up for pop up or modal. The following is the code I have written to do the job (yes it is long but it has to be to accomodate all the user options). Any help would be greatly appreciated.
Private Sub btnOK_Click()
Dim Template As Long
Dim Order As Long
Dim Person As Long
Dim Lists As Long
Template = [Forms]![User Reports]![Report Template]
Order = [Forms]![User Reports]![Report Order By]
Person = [Forms]![User Reports]![Report Person Calling]
Lists = [Forms]![User Reports]![Report List]
Select Case Template
Case Is = 1
Select Case Order
Case Is = 1
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Address List by Call Up List, Agency, Call Order", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up Lists]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Address List by Category, Agency, Call Order", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Address List by Resource, Agency, Call Order", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Address List by Agency, Call Order", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select
Case Is = 2
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Address List by Call Up List, Agency, Name", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Address List by Category, Agency, Name", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Address List by Resource, Agency, Name", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Address List by Agency, Name", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select
End Select
DoCmd.Close acForm, "User Reports", acSaveNo
Case Is = 2
DoCmd.OpenReport "Civil Defense / Volunteer List", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
DoCmd.Close acForm, "User Reports", acSaveNo
Case Is = 3
Select Case Lists
Case Is = 1
DoCmd.OpenReport "E-Mail List by Call Up List", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "E-Mail List by Category", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "E-Mail List by Resource", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "E-Mail List by Agency", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select
DoCmd.Close acForm, "User Reports", acSaveNo
Case Is = 4
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Label List by Call Up List", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Label List by Category", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Label List by Resource", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Label List by Agency", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select
DoCmd.Close acForm, "User Reports", acSaveNo
Case Is = 5
Select Case Order
Case Is = 1
Select Case Person
Case Is = 1
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Phone List by Caller, Call Up, Agency, Call Order", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Phone List by Caller, Category, Agency, Call Order", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Phone List by Caller, Resource, Agency, Call Order", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Phone List by Caller, Agency, Call Order", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select 'Lists
Case Is = 2
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Phone List by Call Up, Agency, Call Order", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Phone List by Category, Agency, Call Order", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Phone List by Resource, Agency, Call Order", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Phone List by Agency, Call Order", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select 'Lists
End Select 'Person
Case Is = 2
Select Case Person
Case Is = 1
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Phone List by Caller, Call Up, Agency, Name", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Phone List by Caller, Category, Agency, Name", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Phone List by Caller, Resource, Agency, Name", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Phone List by Caller, Agency, Name", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select 'Lists
Case Is = 2
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Phone List by Call Up, Agency, Name", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Phone List by Category, Agency, Name", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Phone List by Resource, Agency, Name", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Phone List by Agency, Name", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select 'Lists
End Select 'Person
End Select 'Order
DoCmd.Close acForm, "User Reports", acSaveNo
Case Is = 6
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Sign In List by Call Up List", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Sign In List by Category", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Sign In List by Resource", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Sign In List by Agency", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select
DoCmd.Close acForm, "User Reports", acSaveNo
Case Else
Exit Sub
End Select
End Sub
Private Sub btnOK_Click()
Dim Template As Long
Dim Order As Long
Dim Person As Long
Dim Lists As Long
Template = [Forms]![User Reports]![Report Template]
Order = [Forms]![User Reports]![Report Order By]
Person = [Forms]![User Reports]![Report Person Calling]
Lists = [Forms]![User Reports]![Report List]
Select Case Template
Case Is = 1
Select Case Order
Case Is = 1
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Address List by Call Up List, Agency, Call Order", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up Lists]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Address List by Category, Agency, Call Order", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Address List by Resource, Agency, Call Order", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Address List by Agency, Call Order", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select
Case Is = 2
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Address List by Call Up List, Agency, Name", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Address List by Category, Agency, Name", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Address List by Resource, Agency, Name", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Address List by Agency, Name", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select
End Select
DoCmd.Close acForm, "User Reports", acSaveNo
Case Is = 2
DoCmd.OpenReport "Civil Defense / Volunteer List", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
DoCmd.Close acForm, "User Reports", acSaveNo
Case Is = 3
Select Case Lists
Case Is = 1
DoCmd.OpenReport "E-Mail List by Call Up List", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "E-Mail List by Category", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "E-Mail List by Resource", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "E-Mail List by Agency", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select
DoCmd.Close acForm, "User Reports", acSaveNo
Case Is = 4
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Label List by Call Up List", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Label List by Category", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Label List by Resource", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Label List by Agency", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select
DoCmd.Close acForm, "User Reports", acSaveNo
Case Is = 5
Select Case Order
Case Is = 1
Select Case Person
Case Is = 1
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Phone List by Caller, Call Up, Agency, Call Order", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Phone List by Caller, Category, Agency, Call Order", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Phone List by Caller, Resource, Agency, Call Order", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Phone List by Caller, Agency, Call Order", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select 'Lists
Case Is = 2
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Phone List by Call Up, Agency, Call Order", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Phone List by Category, Agency, Call Order", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Phone List by Resource, Agency, Call Order", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Phone List by Agency, Call Order", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select 'Lists
End Select 'Person
Case Is = 2
Select Case Person
Case Is = 1
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Phone List by Caller, Call Up, Agency, Name", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Phone List by Caller, Category, Agency, Name", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Phone List by Caller, Resource, Agency, Name", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Phone List by Caller, Agency, Name", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select 'Lists
Case Is = 2
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Phone List by Call Up, Agency, Name", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Phone List by Category, Agency, Name", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Phone List by Resource, Agency, Name", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Phone List by Agency, Name", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select 'Lists
End Select 'Person
End Select 'Order
DoCmd.Close acForm, "User Reports", acSaveNo
Case Is = 6
Select Case Lists
Case Is = 1
DoCmd.OpenReport "Sign In List by Call Up List", acViewPreview, , "[Call Up List ID]=[Forms]![User Reports]![Report Call Up List]"
DoCmd.Maximize
Case Is = 2
DoCmd.OpenReport "Sign In List by Category", acViewPreview, , "[Category ID]=[Forms]![User Reports]![Report Category]"
DoCmd.Maximize
Case Is = 3
DoCmd.OpenReport "Sign In List by Resource", acViewPreview, , "[Resource ID]=[Forms]![User Reports]![Report Resource]"
DoCmd.Maximize
Case Is = 4
DoCmd.OpenReport "Sign In List by Agency", acViewPreview, , "[Agency ID]=[Forms]![User Reports]![Report Agency]"
DoCmd.Maximize
Case Else
Exit Sub
End Select
DoCmd.Close acForm, "User Reports", acSaveNo
Case Else
Exit Sub
End Select
End Sub