diff --git a/pgadmin/frm/frmQuery.cpp b/pgadmin/frm/frmQuery.cpp
index 45a07ea..43b1fb8 100644
--- a/pgadmin/frm/frmQuery.cpp
+++ b/pgadmin/frm/frmQuery.cpp
@@ -1158,6 +1158,8 @@ void frmQuery::OnChangeNotebook(wxAuiNotebookEvent &event)
 	wxWindow *win = wxWindow::GetCapture();
 	if (win)
 		win->ReleaseMouse();
+	else
+		return;
 
 	if(sqlNotebook && sqlNotebook->GetPageCount() >= 2)
 	{
