Question Open Form To add New Record

Robert

New member
Joined
Jun 11, 2008
Messages
3
Location
UK, Kent
Programming Experience
Beginner
I have a form which has has a bound data source (generated automatically by VB - table adapter, binding source etc).

How do I use the Form.Show method to open the form ready to enter a new record. Is there a simple way of doing this?
 
Firstly, thanks for the reply - very useful link.

Found a very simple answer to this - effectively I needed to open the bound form and mimic the user pressing the "+" Add New button (on the Binding Navigator) - i.e. so it's ready for the user to enter a new record. This can be done very simply using the "Add New" button's "PerformClick()" method.

I just need to tell the form that the user wishes to add a new record by passing an ID value of "-1" across before using its form.show method (or whatever flag you wish to use to achieve this).

Example:

In the form's load event....

If RecID = -1 Then 'i.e. this is a new record
Me.BindingNavigatorAddNewItem.PerformClick()
Else 'This is an exisiting record so filter on the selected record ID param
'Fill the dataset - note there is an ID parameter
Me.TblTelListTableAdapter.FillByRecID(Me.UranusDataSet.tblTelList, RecID)
End If

Hope this helps.....

Regards
 
I have a form which has has a bound data source (generated automatically by VB - table adapter, binding source etc).

How do I use the Form.Show method to open the form ready to enter a new record. Is there a simple way of doing this?

Hi Robert,

Did you ever find out how to do this? I'm trying to do the same thing.

Thanks,
Tom
 
Hi Tom

I discovered a simple way of doing this by making use of the "PerformClick()" method of the "Add New" button on the Binding Navigator (which is added automatically when the wizard creates your bound form).

When the user clicks the [Add New Record] button on the main form, it .shows (opens) the data input form. To simulate the User clicking the "Add New" button on the data input form's Binding Navigator, I simply placed the following code in the click event of the main forms "New Record" button (or something along these lines):

frmNewRecord.Show 'show the input form
frmNewRecord.bttnAddNew.PerformClick 'simulate the user clicking the "Add New" button on it's binding navigator

You may also want to pass across the main records unique ID for the foreign key field etc. in the code above (e.g. if you are adding orders to a customer etc.).

Hope this helps you.

Bottom line - expore the PerformClick event - it's handy.

Regards

Robert
 
Back
Top