I'm opening in report view; yes, I'm trying to open using the runtime interface so I can distribute to people without the full version of Access. The report is calling the form, then hiding it once the data is input.
Code:
Option Compare Database
Option Explicit
Private Sub Report_Close()
DoCmd.Close acForm, "Cv Search"
End Sub
Private Sub Report_Open(Cancel As Integer)
' Set public variable to true to indicate that the report
' is in the Open event
bInReportOpenEvent = True
' Open Cv Search Dialog
DoCmd.OpenForm "Cv Search", , , , , acDialog
' Cancel Report if User Clicked the Cancel Button
If IsLoaded("Cv Search") = False Then Cancel = True
' Set public variable to false to indicate that the
' Open event is completed
bInReportOpenEvent = False
End Sub
The support module:
Code:
Option Compare Database
Option Explicit
Public bInReportOpenEvent As Boolean ' Is report in the Open event?
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or
' Datasheet view.
Dim oAccessObject As AccessObject
Set oAccessObject = CurrentProject.AllForms(strFormName)
If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign Then
IsLoaded = True
End If
End If
End Function
And the form code:
Code:
Option Compare Database
Option Explicit
Private Sub Command14_Click()
Me.Visible = False
End Sub
Private Sub Command15_Click()
DoCmd.Close 'Close Form
End Sub
Private Sub Form_Open(Cancel As Integer)
If Not bInReportOpenEvent Then
' If we're not called from the report
MsgBox "For use from the Cv Report only", _
vbOKOnly
Cancel = True
End If
Form_Open_Exit:
Exit Sub
End Sub