Vallidation check for a search form based on a report

mercury

Registered User.
Local time
Today, 01:02
Joined
Jul 17, 2004
Messages
35
hello there,
I would like to know how to do a validation check, so that if a person chooses a particular option from a drop down menue and no information was written about that particular company, a message would appear stating that no information was entered regarding that company therefore the a report would not pop up. The client would be using a search form, to choose the company they want to find out information about........... I got everything else working already and even tho it seems like a small problem its giving me a lot of trouble.

Here is the code i have already:

Code:
Private Sub Command4_Click()
 Dim pstrCriteria As String
    If IsNull([txtSearch]) Then
        MsgBox " Please enter search criteria"
       
    Else
        'If legal Company Name entered, form criteria, and print
        If txtSearch <> " " Then
            pstrCriteria = "[CompanyName] = " & Chr$(34) & txtSearch & Chr$(34)

            DoCmd.OpenReport "Ideal Optical Business Solutions", acViewPreview, , pstrCriteria
     
        End If
    End If
End Sub

Who ever can help me out i would really appreciate it.........
 
on the NoData event of the report enter the following;

msgbox "There is no information for the chosen company"
cancel=true

Unfotunately the report will stat to open, but the message will then pop-up and as soon as the user click the 'OK' button on the msgbox, the report will close.
 
Hi

It worked but the thing is i keep getting this run time error which says "The OpenReport action was cancelled" could you or someone tell me what is wrong i figured it is something with the code i have in my search form anyway if you would like to see what im talking about just view the database i attached open the search form and select "K+M" from the combo box and click search then you will see what im talking about.

What i realised is that it is cancelled in the report but still is opening in the search form since i have:
DoCmd.OpenReport "Ideal Optical", acViewPreview, , pstrCriteria

i dont have anything to cancel the opening of the report in my search form (i wonder if anyone understand what i just typed )...anyway could someone help me out?

Mercury
 

Attachments

On the search form before:

Code:
DoCmd.OpenReport "Ideal Optical", acViewPreview, , pstrCriteria

enter the code:

Code:
on error resume next

This should stop any error messages being displayed
 

Users who are viewing this thread

Back
Top Bottom