Tony said:
Marshall here is my code behind the command button on the prompt form
Private Sub cmdRunReport_Click()
Dim stDocName As String
stDocName = "rptDocumentbyKeyword"
If IsNull(Me.findkeywordtxt) Then MsgBox "Please enter Keyword"
Me.findkeywordtxt.SetFocus
Cancel = True
If IsNull(Me.StartDatetxt) Then MsgBox "Please enter Start Date"
Me.StartDatetxt.SetFocus
Cancel = True
If IsNull(Me.EndDatetxt) Then MsgBox "Please enter End Date"
Me.EndDatetxt.SetFocus
Cancel = True
If Not IsNull(StartDatetxt) And Not IsNull(EndDatetxt) And Not
IsNull(findkeywordtxt) Then
DoCmd.OpenReport stDocName, acPreview
End If
Exit_cmbViewReport_Click:
Exit Sub
Err_cmbViewReport_Click:
MsgBox Err.Description
Resume Exit_cmbViewReport_Click
End Sub
This is the code I have put in the header sections Format event
Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
Me.keywordparatxt = [Forms]![frmFindkeyword]![findkeywordtxt]
DoCmd.Close acForm, "frmFindkeyword"
End Sub
However I get error 2450 Access can't find "frmFindkeyword"
Why is this because there is nothing in the command code that closes the
form and the from name is correct? Any ideas?
"Marshall Barton" wrote
Your If logic has a fatal flaw. It should look more like:
If IsNull(Me.findkeywordtxt) Then
MsgBox "Please enter Keyword"
Me.findkeywordtxt.SetFocus
Cancel = True
ElseIf IsNull(Me.StartDatetxt) Then
MsgBox "Please enter Start Date"
Me.StartDatetxt.SetFocus
Cancel = True
ElseIf IsNull(Me.EndDatetxt) Then
MsgBox "Please enter End Date"
Me.EndDatetxt.SetFocus
Cancel = True
Else
DoCmd.OpenReport stDocName, acPreview
End If
However, I don't think that's the source of the error
message. How do the findkeywordtxt, StartDatetxt and
EndDatetxt text boxes interact with the report? Is it
possible that the report has a reference to one of those
after you've closed the form?