Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable from form doesn't show on report No_Data msg

Status
Not open for further replies.

jo2004hi

Technical User
Aug 18, 2006
4
US
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):
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
FORM CODE:
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
 
I think you either need to move the message in the error coding from the No Data event to the calling form, which is where error 2501 will occur, or else simply code the message in the No Data event.
 
Thank you Remou!

I had considered the option of using the calling form but am unsure how to code for it. I have an on error event for the button to trap a 2501 error but it doesn't fire.

The message is coded in the No Data event of the report. The msgbox comes up but the variable is empty.

Thanks for your assistance.

Jo
 
I tried this and the message box came up with the variable, however, at the start of the form procedure I typed:

strSearch="ABC"

I wonder if the problem is that strSearch is not picked up?

PS I do not think this will work:
Reports![rptKeywordSearch]![strRptKeyword] = strSearch
 
You're correct that strSearch is not picked up from the form which is why I assigned the value to a text box and referenced the text box in the msgbox.

Both the msgbox and the variable worked when there was no data until I changed the .visible mode of the calling form from the Form_open event.

Jo
 
There is a misunderstanding. I ran your code as you posted it, except that I set strSearch. Do not hide the form, I think you will find that the textbox is blank and therefore the message box shows nothing.
 
Thanks again for your assistance. I've removed the "offending" code and it runs just fine. I appreciate you checking the code.

Jo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top