I am having this strange error/conflict. I have two forms in my application. Both have same namespaces, and when I try to create an object of the next form it doesn't shows up. This is my code in Form1
Form2 form2 = new Form2();
form2.Show();
this.Hide();
And when I add another form in the project (like form3.cs) it shows up. Why is this "form2" missing? Although it is available in the project.
Form 1 code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.SqlServerCe;
using UHF_Demo;
namespace UHF_Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void submit_Click(object sender, EventArgs e)
{
{
string query = "Select * from login_info where username = '" + username_tb.Text + "' and password = '" + password_tb.Text + "'";
SqlCeConnection conn = new SqlCeConnection();
conn.ConnectionString = #"Data Source =\Program Files\valcan\employeedb.sdf";
SqlCeCommand cmd = new SqlCeCommand(query, conn);
conn.Open();
SqlCeDataReader dr = cmd.ExecuteReader();
int counter = 0;
while (dr.Read())
{
counter = counter + 1;
}
if (counter > 0)
{
Form2 form2 = new Form2();
form2.Show();
this.Hide();
}
else
{
MessageBox.Show("Invalid Login name or Password. Please try again ....");
}
conn.Close();
dr.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'locationds.login_info' table. You can move, or remove it, as needed.
this.login_infoTableAdapter.Fill(this.locationds.login_info);
}
}
}
}}
Form2 code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.Globalization;
using System.IO;
namespace UHF_Demo
{
public partial class MR6651_DEMO : Form
{
public bool BeingId = false;
byte[,] TagBuf = new byte[100, 14];
byte TagCnt = 0;
ComPort Port0 = new ComPort();
private CultureInfo culinfo = CultureInfo.CurrentCulture;
public MR6651_DEMO()
{
InitializeComponent();
double CostomiseFQ = 900.000;
for (int i = 0; i < 60; i++)
{
comboBox1.Items.Add(CostomiseFQ.ToString("#0.000")+"M");
comboBox2.Items.Add(CostomiseFQ.ToString("#0.000") + "M");
CostomiseFQ +=0.5;
}
MEMBANK.SelectedIndex = 1;
WORDPTR.SelectedIndex = 0;
WORDCNT.SelectedIndex = 0;
cmbFreqType.SelectedIndex = 2;
VALUE.Text = "";
//tabPage3.Parent = null;
if (culinfo.ToString() == "zh-CN")
{
this.Text = "UHF¶ÁдÑÝʾ";
TabPage page1 = tabControl1.TabPages[0];
page1.Text = "»¶Ó";
TabPage page2 = tabControl1.TabPages[1];
page2.Text = "EPC²âÊÔ";
//TabPage page3 = tabControl1.TabPages[2];
//page3.Text = "6B²âÊÔ";
label5.Text = "¹¦ÂÊ";
label8.Text = "ƵÂÊ";
labStatusBar.Text = "×¼±¸¾ÍÐ÷";
btnQueryPower.Text = "²éѯ";
btnSetPower.Text = "ÉèÖÃ";
EXIT.Text = "Í˳ö";
chkAutoClr.Text = "¹ýÂËÖظ´±êÇ©";
ID.Text = "ʶ±ð";
btnEPClist.Text = "Áбí";
button1.Text = "EPC¿é²Ù×÷";
CLEAR.Text = "Çå¿Õ";
label2.Text = "×ÖµØÖ·";
label3.Text = "×Ö³¤¶È";
label4.Text = "Êý¾Ý";
READ.Text = "¶ÁÈ¡";
WRITE.Text = "дÈë";
INIT.Text = "³õʼ»¯";
label10.Text = "×Ö½ÚµØÖ·";
label7.Text = "×Ö½Ú³¤¶È";
label9.Text = "Êý¾Ý";
btn6BID.Text = "ʶ±ð";
btn6BRead.Text = "¶ÁÈ¡";
btn6BWrite.Text = "дÈë";
btn6BLock.Text = "Ëø¶¨";
chkClear6B.Text = "¹ýÂËÖظ´±êÇ©";
btn6BClear.Text = "Çå¿Õ";
btnSaveFile.Text = "±£´æÎļþ";
label1.Text = "Êý¾Ý¿é";
cmbFreqType.Items.Clear();
cmbFreqType.Items.Add("Öйú");
cmbFreqType.Items.Add("±±ÃÀ");
cmbFreqType.Items.Add("Å·ÖÞ");
cmbFreqType.Items.Add("×Ô¶¨Òå");
cmbFreqType.SelectedIndex = 2;
listViewEPC.Columns[0].Text = "EPCÂë";
listViewEPC.Columns[1].Text = "񅧏";
label11.Text = "ÆðʼƵµã";
label12.Text = "ÖÕֹƵµã";
btn_locktid.Text = "ËøTID";
btn_seelocktid.Text = "²é¿´TIDËø";
}
}
private void EPC_DEMO_Load(object sender, EventArgs e)
{
if (Port0.Open() == 0)
{
if (culinfo.ToString() == "zh-CN")
{
labStatusBar.Text = "ͨѶ¶Ë¿Ú´ò¿ª³É¹¦!";
}
else
{
labStatusBar.Text = "Start conmunicate commport success!";
}
//aStatus = Port0.SetRf(10, 2);
Thread.Sleep(500);
btnQueryPower_Click(sender, e);
Sound.PlayWAV(#"\Application Data\Rfid\wav\shutter.wav");
for (int i = 0; i < 223; i++)
ADDR6B.Items.Add(i.ToString());
ADDR6B.SelectedIndex = 0;
ByteCnt6B.SelectedIndex = 0;
}
}
You have no Form2 class. You've got a MR6651_DEMO class. Try creating an instance of that instead. Your compiler should be telling you exactly what's wrong.
The name of a file doesn't have to have anything to do with the class contained within - that they often match is a matter of hygiene and sanity. =)
In your Form 2 Code there is no Class Definition for a Class named Form2. I guess thats the cause why it can't be found.
Related
Every time when I click the button only one row will be displayed. But it should show multiple rows. I declare the list after the constructor invoke. I tried with gridview.update() and gridview.refresh() but they didn't work. I could not findout the issue.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using JournalEntryApp.Model;
namespace JournalEntryApp
{
public partial class NewDocument : Form
{
public NewDocument()
{
InitializeComponent();
}
List<JEFrom> JEFromsList = new List<JEFrom>();
List<JETo> JETosList = new List<JETo>();
JEFrom _jef = null;
private void NewDocument_Load(object sender, EventArgs e)
{
label4.Text = DateTime.Now.ToString("dd-MMM-yyyy");
using (var db =new JournalContext())
{
unitComboBox.DataSource = db.Units.ToList();
unitComboBox.ValueMember = "Id";
unitComboBox.DisplayMember = "UnitName";
}
}
private void addToListButton_Click(object sender, EventArgs e)
{
if (string.Empty== fromAccountTextBox.Text)
{
MessageBox.Show("From Account can not be empty!!!");
}
else if (string.Empty == toAccountTextBox.Text)
{
MessageBox.Show("To Account can not be empty!!!");
}
else
{
_jef = new JEFrom{ FromEntryName= fromAccountTextBox.Text , FromEntryDate= DateTime.Now };
JEFromsList.Add(_jef);
temporaryDataGridView.DataSource = JEFromsList;
fromAccountTextBox.Text = string.Empty;
toAccountTextBox.Text = string.Empty;
}
}
}
}
The temporaryDataGridView cannot detect that you have changed the DataSource. It will only refresh when Datasource has changed.
temporaryDataGridView.DataSource = null;
temporaryDataGridView.DataSource = JEFromsList;
so change the Datasource null first.
Or you can use bindingSource
private void NewDocument_Load(object sender, EventArgs e)
{
this.bindingSource1.DataSource = JEFromsList;
temporaryDataGridView.DataSource = this.bindingSource1;
label4.Text = DateTime.Now.ToString("dd-MMM-yyyy");
using (var db =new JournalContext())
{
unitComboBox.DataSource = db.Units.ToList();
unitComboBox.ValueMember = "Id";
unitComboBox.DisplayMember = "UnitName";
}
}
in button_click
JEFromsList.Add(_jef);
bindingSource1.ResetBindings(true);
I have written a news web application. I think code is right but it return false when the function Add news is called
/*my form
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
using WindowsFormsApp1.Models;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
byte[] picture = null;
WebClient ObjWebClient = null;
List<CategoriesGET>ListCategories = null;
public Form1()
{
InitializeComponent();
//---------------------------------
ObjWebClient = new WebClient();
ObjWebClient.Headers[HttpRequestHeader.ContentType]= "application/json ; charset=utf-8";
string url = "http://localhost:3712/api/CategoriesApi/GetCategories";
string JsonResponse = ObjWebClient.DownloadString(url);
ListCategories = JsonConvert.DeserializeObject<List<CategoriesGET>>(JsonResponse);
cmb_NewsCategories.DataSource = ListCategories.Select(q=>q.CategoryTitle).ToList();
}
private void RefreshForms()
{
Txt_NewsTitle.Text = string.Empty;
Txt_NewsDescription.Text = string.Empty;
Txt_NewsDescription.Text = "لطفا دسته خبر را انتخاب کنید";
NewsImage.Image = Properties.Resources._2;
}
private void button3_Click(object sender, EventArgs e)
{
string url = "http://localhost:3712/api/NewsApi/AddNews/?NewsJson=";
ObjWebClient = new WebClient();
ObjWebClient.Headers[HttpRequestHeader.ContentType] = "application/json ; charset=utf-8";
ObjWebClient.Encoding = UTF8Encoding.UTF8;
//-------------------------------
PostNewsModel ObjPost = new PostNewsModel();
ObjPost.NewsTitle = Txt_NewsTitle.Text;
ObjPost.NewsDescription = Txt_NewsDescription.Text;
ObjPost.FK_CategoryID = ListCategories[cmb_NewsCategories.SelectedIndex].CategoryID;
ObjPost.NewsPicture = picture;
//-------------------------------------------------
string JsonData = JsonConvert.SerializeObject(ObjPost);
string Response = ObjWebClient.UploadString(url, JsonData);
MessageBox.Show(Response);
}
private void button4_Click(object sender, EventArgs e)
{
OpenFileDialog OFD = null;
string ImgPath = null;
OFD = new OpenFileDialog();
OFD.Title = "انتخاب عکس";
OFD.Filter = "JpegFiles|*.jpg";
if (OFD.ShowDialog() == DialogResult.OK)
{
if(OFD.FileName != null)
{
ImgPath = OFD.FileName;
NewsImage.Image = System.Drawing.Image.FromFile(ImgPath);
picture = AppClasses.Utility.ConvertImageToByte(NewsImage.Image, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
private void Txt_NewsTitle_TextChanged(object sender, EventArgs e)
{
}
}
}
//Add news function
public bool AddNews([FromBody]TB_News_Post NewsJson)
{
bool Succesfull =false;
try
{
string ImageLabel = GeneratePicName();
string Picture = ByteToImage(NewsJson.NewsPicture, ImageLabel);
TB_News Tbl_News = new TB_News();
Tbl_News.FK_CategoryID = NewsJson.FK_CategoryID;
Tbl_News.NewsDescription = NewsJson.NewsDescription;
Tbl_News.NewsPicture = Picture;
Tbl_News.NewsTitle = NewsJson.NewsTitle;
Tbl_News.NewsDate = DateTime.Now;
DbContext.TB_News.Add(Tbl_News);
DbContext.SaveChanges();
Succesfull = true;
}
catch (Exception)
{
Succesfull = false;
}
return Succesfull;
please help and feel free to ask the whole project thnx a lot
I’m trying to create a webpage that displays dynamically placed WebUserControls depending on a question type that is returned from and SQL server. When you press a button on the usercontrols it checks the result from the usercontrol using the procedure “CheckResult”. For some reason when you click on the buttons within the usercontrols ("cmdProcess") the Event “CheckResult” does not fire. What am I doing wrong please?
The User control code is: -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Testing.Event_Delegate
{
public partial class WebUserControl2 : System.Web.UI.UserControl
{
// Delegate declaration
public delegate void PhotoUploaded(string strFilename, String FailureMessage, string strFabricationNo, string strPartNo, string strBatchNo, string strPartSN, string strSTK_SerialNo, string strSTK_PartNo);
// Event declaration
public event PhotoUploaded Resultresponse;
string questionAsked;
public string QuestionText
{
set { questionAsked = value; }
get { return questionAsked; }
}
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = QuestionText;
TextBox1.Focus();
}
protected void cmdProcess_Click(object sender, EventArgs e)
{
if (Resultresponse != null)
{
Resultresponse("Passed", "", "", "", "", "", "", "");
}
TextBox1.Text = "";
}
}
}
And the main ASPX page that the usercontrols are placed on is: -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace Testing.Event_Delegate
{
public partial class WebForm1 : System.Web.UI.Page
{
WebUserControl2 QT2;
WebUserControl3 QT3;
DataTable dtQuestionSet;
protected void Page_Load(object sender, EventArgs e)
{
// all controls need to be rendered every page postback otherwise the rest of the code loses scope.
QT2 = (WebUserControl2)this.LoadControl("WebUserControl2.ascx");
QT3 = (WebUserControl3)this.LoadControl("WebUserControl3.ascx");
if (IsPostBack == false)
{
Session["Counter"] = 0;
Session["QuestionCount"] = 0;
Session["CompletedInsp"] = false;
Session["RunInsp"] = false;
dtQuestionSet = new DataTable();
MakeDataTabledtQuestionSet();
}
else
{
dtQuestionSet = (DataTable)Session["DataTableW"];
//check to see if the inspection process is complete and display pass\fail and log. Else carry on.
if (Convert.ToBoolean(Session["CompletedInsp"]) == true)
{
//Response.Write("Failed");
ModalPopupExtender2.Show();
return;
}
}
Session["DataTableW"] = dtQuestionSet;
}
void CheckResult(string Result, string FailureMessage, string FabricationNo, string PartNo, string BatchNo, string PartSN, string STK_SerialNo, string STK_PartNo)
{
Label1.Text = "You Answered: - " + Result;
if ((Convert.ToInt32(Session["Counter"]))>= Convert.ToInt32(Session["QuestionCount"]))
{
Session["CompletedInsp"] = true;
Session["RunInsp"] = false;
}
else
{
dtQuestionSet = (DataTable)Session["DataTableW"];
}
Session["Counter"] = Convert.ToInt32(Session["Counter"]) + 1;
//If the inspection hasn't been completed carry on and ask next question.
if (Convert.ToBoolean(Session["RunInsp"]) == true)
{
RunInspection();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm1.aspx");
}
protected void cmdStartInspection_Click(object sender, EventArgs e)
{
Session["Counter"] = 0;
GetQuestions();
}
protected void GetQuestions()
{
dtQuestionSet.Clear();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["PromptedInspConnectionString"].ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand("test.GetQuestions", conn);
SqlDataReader dr = null;
cmd.CommandType = CommandType.StoredProcedure;
dr = cmd.ExecuteReader();
while (dr.Read())
{
DataRow drQuestions = dtQuestionSet.NewRow();
drQuestions["QuestionText"] = dr[1].ToString();
drQuestions["ExpectedResponse"] = dr[2].ToString();
drQuestions["QuestionType"] = dr[3].ToString();
dtQuestionSet.Rows.Add(drQuestions);
}
Session["DataTableW"] = dtQuestionSet;
Session["QuestionCount"] = dtQuestionSet.Rows.Count;
conn.Close();
RunInspection();
Session["RunInsp"] = true;
}
protected void RunInspection()
{
//Populate the user controls
switch (dtQuestionSet.Rows[Convert.ToInt32(Session["counter"])][2].ToString())
{
case "1":
QT2.QuestionText = dtQuestionSet.Rows[Convert.ToInt32(Session["counter"])][0].ToString();
QT2.Resultresponse += new WebUserControl2.PhotoUploaded(CheckResult);
break;
case "2":
QT3.QuestionText = dtQuestionSet.Rows[Convert.ToInt32(Session["counter"])][0].ToString();
QT3.Resultresponse += new WebUserControl3.PhotoUploaded(CheckResult);
break;
}
//Add the usercontrols to the form
PlaceHolder2.Controls.Add(QT2);
PlaceHolder2.Controls.Add(QT3);
//Need to set the visability of the usercontrol so it only shows the usercontrol that is displaying the question
QT2.Visible = false;
QT3.Visible = false;
switch (dtQuestionSet.Rows[Convert.ToInt32(Session["counter"])][2].ToString())
{
case "1":
QT2.Visible = true;
break;
case "2":
QT3.Visible = true;
break;
}
}
private void MakeDataTabledtQuestionSet()
{
dtQuestionSet.Columns.Add("QuestionText");
dtQuestionSet.Columns.Add("ExpectedResponse");
dtQuestionSet.Columns.Add("QuestionType");
}
}
}
Try initializing the controls in OnPreInit rather than load. Controls binding is done in OnPreInit.
See the page lifecyle events MSDN Reference
so I have my Winform, in which I have a dgv with data in it, and I need to be able to save that data into two separated arraylists when the appropiate cell is clicked.
No problem with that really, but I hav which might be possibly the dumbest error to be ever programmed:
I need to instance the class where the arraylists are, "clsAL", but the programme still throws an error, arguing that the "Object reference not set to an instance of an object". Here's the code (ingore anything that has nothing to do with this, specially if it's in spanish :D)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication7
{
public partial class FormH : Form
{
clsAL cls;
public FormH()
{
InitializeComponent();
}
private void FormH_Load(object sender, EventArgs e)
{
cls = new clsAL();
OleDbCommand comm;
OleDbConnection conn = new OleDbConnection();
DataSet dset;
OleDbDataAdapter adap = new OleDbDataAdapter();
OleDbCommandBuilder cmb;
conn.ConnectionString = "Provider = 'Microsoft.Jet.OLEDB.4.0'; Data Source = 'RoboTIC.mdb'";
comm = new OleDbCommand("Select * From tblHistorial", conn);
adap = new OleDbDataAdapter(comm);
dset = new DataSet();
adap.Fill(dset, "tblHistorial");
dgvHistorial.DataSource = dset.Tables["tblHistorial"];
}
private void dgvHistorial_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
cls = new clsAL();
string operacion = dgvHistorial.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
cls.dir.Clear();
cls.time.Clear();
string aux = "";
for (int a = 0; a > operacion.Length; a++)
{
aux = aux + operacion[a];
if (aux == "a")
{
cls.dir.Add("avanzar");
}
if (aux == "d")
{
cls.dir.Add("derecha");
}
if (aux == "i")
{
cls.dir.Add("izquierda");
}
if (aux == "r")
{
cls.dir.Add("retroceder");
}
if (aux == "/")
{
}
if (aux != "a" && aux != "a" && aux != "a" && aux != "a" && aux != "/")
{
cls.time.Add(Convert.ToInt32(operacion[a]+operacion[a+1]));
}
}
}
}
}
The problem is with the dir arraylist in clsAl. This is a NullReferenceException. It is because you haven't allocated the dir arraylist at the time you're trying to call Clear() on it.
In the constructor for clsAl add
clsAl()
{
dir = new ArrayList();
time = new ArrayList();
}
and you will stop getting these exceptions.
I am adding records to my database via a windows form. But when ever I add a new record it doesnt update until I close the app and then start again. Even though I think I am telling it to update (Im obv not!!)
Do I need a new varibale to update the database? Im a little stuck.
EDIT: All code on this..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace MediaManagementSystem
{
public partial class AddMedia : Form
{
//database var
OleDbConnection m_cnADONetConnection = new OleDbConnection();
OleDbDataAdapter m_daDataAdapter;
OleDbDataAdapter m_cbCommandBuilder;
DataTable m_dtMedia = new DataTable();
int m_rowPosition = 0;
public AddMedia()
{
InitializeComponent();
}
private void BrowseButton_Click(object sender, EventArgs e)
{
//load up file dialog and find media
if (addFileDialog.ShowDialog() == DialogResult.OK)
{
//add media file name to file path text box
txtFilePath.Text = addFileDialog.FileName;
}
}
private void CancelButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void AddButton_Click(object sender, EventArgs e)
{
//add the new record to the database
DataRow drNewRow = m_dtMedia.NewRow();
drNewRow["FilePath"] = txtFilePath.Text;
drNewRow["Subject"] = txtSubject.Text;
drNewRow["Title"] = txtTitle.Text;
drNewRow["Keywords"] = txtKeywords.Text;
drNewRow["MediaType"] = AddComboBox.Text;
m_dtMedia.Rows.Add(drNewRow);
m_daDataAdapter.Update(m_dtMedia);
m_rowPosition = m_dtMedia.Rows.Count - 1;
this.ShowCurrentRecord();
this.Close();
}
private void AddMedia_Load(object sender, EventArgs e)
{
//link to the database and conect to database
m_cnADONetConnection.ConnectionString = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Max\Documents\Visual Studio 2010\Projects\MediaManagementSystem\MediaManagementSystem\bin\Debug\MediaDB.mdb";
m_cnADONetConnection.Open();
OleDbConnection objConnection = new OleDbConnection(m_cnADONetConnection.ConnectionString);
m_daDataAdapter = new OleDbDataAdapter("Select * From Media", m_cnADONetConnection);
OleDbCommandBuilder m_cbCommandBuilder = new OleDbCommandBuilder(m_daDataAdapter);
m_daDataAdapter.Fill(m_dtMedia);
m_daDataAdapter.Update(m_dtMedia);
}
public void ShowCurrentRecord()
{
m_daDataAdapter.Update(m_dtMedia);
if (m_dtMedia.Rows.Count == 0)
{
txtFilePath.Text = "";
txtSubject.Text = "";
txtTitle.Text = "";
txtKeywords.Text = "";
AddComboBox.Text = "";
return;
}
txtFilePath.Text = m_dtMedia.Rows[m_rowPosition]["FilePath"].ToString();
txtSubject.Text = m_dtMedia.Rows[m_rowPosition]["Subject"].ToString();
txtTitle.Text = m_dtMedia.Rows[m_rowPosition]["Title"].ToString();
txtKeywords.Text = m_dtMedia.Rows[m_rowPosition]["Keywords"].ToString();
AddComboBox.Text = m_dtMedia.Rows[m_rowPosition]["MediaType"].ToString();
}
}
}
It would best if you use DataSet and then update the records in it. Finally you need to call AcceptChanges() after the update() command to commit the changes with dataset something as below also reload the data after to enter to get the recent data info:
dataset.AcceptChanges()
After you open AddMedia form from your MAIN form, you need to RALOAD all your records again. Look how the form is doing it when it opens and do the same AFTER you open your AddMedia form ;)