mhuddles

I have a project that currently has two forms. The first (frmStart) is the form that opens on Startup, and the other (frmForm) opens after the Click event "frmForm.show ()". Ideally, frmForm will open so that the user can start adding information for a new record without clicking the record navigation buttons. I would like the code in frmStart to dictate this, but if I have to create multiple copies of frmFrom to open in different circumstances (add new record, search an existing record, etc) I'm okay with that also, I just want the code to work! Any help would be greatly appreciated!

Michelle



Re: Visual Basic Express Edition Open form to new record

James Bragg

Hey Michelle,

I might need a little more info on your forms to help you out, but from the sounds of it, you're using the designer data controls.

Let's say we have a database table called "Employees" and the primary key for the table is "empID". And we used Microsoft's data controls to create a form called frmEmployees.

From any other form in your application you can now call frmEmployees with the following code:

'center the form on the users screen

frmEmployees.StartPosition = FormStartPosition.CenterScreen

'display the form

frmEmployees.Show()

Now you can select the record or row (depending on your upbringing) by doing something like:

'Set the form to show a specific record

frmEmployees.EmployeesBindingSource.Filter = "empID =" & strlEmpID

Or, if you want to add a new row do something like:

'Add a new record

frmEmployees.EmployeesBindingSource.AddNew()

Naturally, this code would be in a button's on click event or other user control event.

Hope this helps & happy coding!






Re: Visual Basic Express Edition Open form to new record

mhuddles

I tried the last line, which I think should have given me the result I wanted, but the form still opened on the first record (Record 1 of 9). I placed the code in the OnClick event of a label in frmStart and in the Load event of frmForm. Here is what I have:

frmForm.Show()

frmForm.TblClearanceBindingSource.AddNew()

or when it is in the Load event of frmForm:

me.TblClearanceBindingSource.AddNew()

What am I missing I'm still trying to get used to the language changes from VB 6.0...

Thanks in advance,

Michelle





Re: Visual Basic Express Edition Open form to new record

James Bragg

Sorry should have mentioned this before,

Check and see if you have the AllowNew property for TblClearanceBindingSource set to True.

Also what type of database are you hitting My example code uses an Access database.






Re: Visual Basic Express Edition Open form to new record

mhuddles

Thanks, I figured it out. My tblClearanceBindingSourceNavigator wasn't pointing to the tblClearenceBindingSource. I am using an Access Database by the way. Thank you so much for helping! I knew it was something simple, but sometimes it is really hard to find the method!

Thanks again,

Michelle





Re: Visual Basic Express Edition Open form to new record

James Bragg

I'm glad you found it!

I've had a tough time transitioning from VB6 too. If you get a chance, pick up David Sceppa's book "Programming Microsoft ADO.NET 2.0 Core Reference" It reads well, and thuroughly explains the new way of doing things under ADO.NET. A light bulb went off when I saw his diagram on page 5 discussing connected and disconnected classes.