diff --git a/pgadmin/frm/frmQuery.cpp b/pgadmin/frm/frmQuery.cpp
index 033f55c..65d5eda 100644
--- a/pgadmin/frm/frmQuery.cpp
+++ b/pgadmin/frm/frmQuery.cpp
@@ -1633,7 +1633,10 @@ void frmQuery::OpenLastFile()
 		setExtendedTitle();
 		SetLineEndingStyle();
 		UpdateRecentFiles(true);
-		mainForm->UpdateAllRecentFiles();
+		if(mainForm != NULL)
+		{
+			mainForm->UpdateAllRecentFiles();
+		}
 	}
 }
 
