I have a calling form that contains a textbox holding search terms.
1) If the report has data, the search terms print out on the reports' unbound text box.
2) When the report opens, I set .visible for calling form to false.
3) If there is no data, I want the search terms to appear in a msg box.
4) If I put the msgbox in the reports On_Open event the search terms print; but if the msgbox is in No_Data event the search terms is empty.
I'm out of practice in VBA so I'm probably missing the forest for the trees. Your assistance is greatly appreciated.
Jo
REPORT CODE (from on_click event):
FORM CODE:
1) If the report has data, the search terms print out on the reports' unbound text box.
2) When the report opens, I set .visible for calling form to false.
3) If there is no data, I want the search terms to appear in a msg box.
4) If I put the msgbox in the reports On_Open event the search terms print; but if the msgbox is in No_Data event the search terms is empty.
I'm out of practice in VBA so I'm probably missing the forest for the trees. Your assistance is greatly appreciated.
Jo
REPORT CODE (from on_click event):
Code:
Private Sub Report_NoData(Cancel As Integer)
On Error GoTo NoDataError
NoDataError:
'show what search terms couldn't be found
If Err.Number = 2501 Or Err.Number = 0 Then
MsgBox "No CDs found using keyword(s) search on: " & vbCrLf & [Forms]![frmkeywordsearch]![txtSearch] & "." & vbCrLf & "Please try again.", vbExclamation, "No Records"
Cancel = True
End
Else
MsgBox ("Error number is " & Err.Number & "; described as: " & Err.Description & "Please contact support.")
End If
End Sub
Private Sub Report_Open(Cancel As Integer)
'makes calling form, "frmKeywordSearch", not visible
'MsgBox "No CDs found using keyword(s) search on: " & vbCrLf & [Forms]![frmkeywordsearch]![txtSearch] & "." & vbCrLf & "Please try again.", vbExclamation, "No Records"
Application.Forms(gblstrPrevForm).Visible = False
End Sub
Code:
Me.txtSearch = strSearch 'add search string to text box to use on report.
'opens report window in preview mode; sets global string to form name
strDocName = "rptKeywordSearch"
gblstrPrevForm = Me.Name
DoCmd.OpenReport strDocName, acViewPreview
Reports![rptKeywordSearch]![strRptKeyword] = strSearch