diff --git a/mod/data/view.php b/mod/data/view.php
index 6ff22b7..75bc0f3 100644
--- a/mod/data/view.php
+++ b/mod/data/view.php
@@ -469,9 +469,11 @@ if ($showactivity) {
     }
     include('tabs.php');
 
+    $url = new moodle_url('/mod/data/view.php', array('d' => $data->id, 'sesskey' => sesskey()));
+    echo html_writer::start_tag('form', array('action' => $url, 'method' => 'post'));
+
     if ($mode == 'asearch') {
         $maxcount = 0;
-        data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode);
 
     } else {
         // Approve or disapprove any requested records
@@ -712,11 +714,6 @@ if ($showactivity) {
             $nowperpage = $perpage;
         }
 
-        // Advanced search form doesn't make sense for single (redirects list view).
-        if ($maxcount && $mode != 'single') {
-            data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode);
-        }
-
     /// Get the actual records
 
         if (!$records = $DB->get_records_sql($sqlselect, $allparams, $page * $nowperpage, $nowperpage)) {
@@ -743,10 +740,7 @@ if ($showactivity) {
                 echo $OUTPUT->notification(get_string('norecords','data'));
             }
 
-        } else {
-            //  We have some records to print.
-            $url = new moodle_url('/mod/data/view.php', array('d' => $data->id, 'sesskey' => sesskey()));
-            echo html_writer::start_tag('form', array('action' => $url, 'method' => 'post'));
+        } else { //  We have some records to print
 
             if ($maxcount != $totalcount) {
                 $a = new stdClass();
@@ -818,28 +812,6 @@ if ($showactivity) {
                 echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl);
             }
 
-            if ($mode != 'single' && $canmanageentries) {
-                echo html_writer::empty_tag('input', array(
-                        'type' => 'button',
-                        'id' => 'checkall',
-                        'value' => get_string('selectall'),
-                    ));
-                echo html_writer::empty_tag('input', array(
-                        'type' => 'button',
-                        'id' => 'checknone',
-                        'value' => get_string('deselectall'),
-                    ));
-                echo html_writer::empty_tag('input', array(
-                        'class' => 'form-submit',
-                        'type' => 'submit',
-                        'value' => get_string('deleteselected'),
-                    ));
-
-                $module = array('name' => 'mod_data', 'fullpath' => '/mod/data/module.js');
-                $PAGE->requires->js_init_call('M.mod_data.init_view', null, false, $module);
-            }
-
-            echo html_writer::end_tag('form');
         }
     }
 
@@ -848,6 +820,16 @@ if ($showactivity) {
         $records = array();
     }
 
+    if ($mode != 'single' && $canmanageentries) {
+        echo html_writer::empty_tag('input', array('type' => 'button', 'id' => 'checkall', 'value' => get_string('selectall')));
+        echo html_writer::empty_tag('input', array('type' => 'button', 'id' => 'checknone', 'value' => get_string('deselectall')));
+        echo html_writer::empty_tag('input', array('class' => 'form-submit', 'type' => 'submit', 'value' => get_string('deleteselected')));
+
+        $module = array('name'=>'mod_data', 'fullpath'=>'/mod/data/module.js');
+        $PAGE->requires->js_init_call('M.mod_data.init_view', null, false, $module);
+    }
+    echo html_writer::end_tag('form');
+
     // Check to see if we can export records to a portfolio. This is for exporting all records, not just the ones in the search.
     if ($mode == '' && !empty($CFG->enableportfolios) && !empty($records)) {
         $canexport = false;
@@ -868,6 +850,11 @@ if ($showactivity) {
             echo $button->to_html(PORTFOLIO_ADD_FULL_FORM);
         }
     }
+
+    //Advanced search form doesn't make sense for single (redirects list view)
+    if (($maxcount || $mode == 'asearch') && $mode != 'single') {
+        data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode);
+    }
 }
 
 echo $OUTPUT->footer();
