• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 547
  • Last Modified:

Access 2010 Alert Prompt when query in subform shows no results

Hi,

I have a subform who's record source is loaded from a query "qrySchedules_Search_Results1" and who's purpose is to show available "Schedules" in datasheet view.

The parent form has 2 combo boxes and the user has to make a selection from both these and then press the "Search" button (I have vba validation behind the search button to ensure a value is selected from each cbo).

After valid cbo selections have been made, the entire form is refreshed and if there are any "Schedule" results to be shown these will be displayed in the subform.

This is all working fine!!

However, my dilema is that when the subform has no results to show i want a msgbox informing the user of this.

I have put the following code in the "On Load" event of the subform, but this does not seem to work.


Private Sub Form_Load()
    If IsNull(Me.HASchedule_ID) Then
    MsgBox "No Schedules Found"
    End If
End Sub

Any ideas please?
0
andrewpiconnect
Asked:
andrewpiconnect
  • 2
1 Solution
 
mbizupCommented:
Try this:

Private Sub Form_Load()
    Dim rs as dao.recordset
    set rs = me.recordsetclone
    If rs.recordcount = 0  Then
         MsgBox "No Schedules Found"
    End If
End Sub

Open in new window

0
 
mbizupCommented:
Alternatively, place this code in the click event of your search button on the main form, after whatever code you are using to filter the subform:


Private Sub cmdSearch_Click()
      ' Your code for filtering the subform goes here
 
     ' Place this after your filtering code

    Dim rs as dao.recordset
    set rs = me.YourSubformControlName.Form.recordsetclone
    If rs.recordcount = 0  Then
         MsgBox "No Schedules Found"
    End If
    set rs = nothing
End Sub

Open in new window

0
 
andrewpiconnectAuthor Commented:
Excellent.

The first answer yougave only worked if i opened the subform without the parent form.

The second however, worked a treat. Many thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now