How to create a search and select form with another single item form?

  • Thread starter Thread starter jasonfan2000
  • Start date Start date
J

jasonfan2000

Guest
Hi,

I've tried to create a Search and Select form on Visual Basic 2017 by using the DataBindingSource way. I found that it was very easy to use if I link it from a MS Access database file(mdb). However, I want to use this Search and Select form to select a single item which will let me to inspect a single item.

So, I use 2 forms to do it. One is the Search and Select form. The other is the Single item inspect form.

1343710.jpg

The program runs good at first as you can see here:

1343711.jpg

After I close the Single item inspect form(Form 2) and go back to Form1, I will select another item and the screen will display Form 2 again. But this time, the screen will lock automatically for around 1 min and exit.

Every time I run this program will fail when I select the item for the 2nd time. It looks like I have missed something here. Can anyone kindly tell me what else I should add in order to make it run normally?

I did not put that much code there because the whole idea is quite simple.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Public Class Form1
Public CurrRec As Integer
Private Sub StudentBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles StudentBindingNavigatorSaveItem.Click
Me.Validate()
Me.StudentBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.StudentDataSet)

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'StudentDataSet.Student' table. You can move, or remove it, as needed.
Me.StudentTableAdapter.Fill(Me.StudentDataSet.Student)

End Sub

Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
CurrRec = StudentBindingSource.Position
Form2.Show()
End Sub
End Class

Public Class Form2
Private Sub StudentBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles StudentBindingNavigatorSaveItem.Click
Me.Validate()
Me.StudentBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.StudentDataSet)

End Sub

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'StudentDataSet.Student' table. You can move, or remove it, as needed.
Me.StudentTableAdapter.Fill(Me.StudentDataSet.Student)
StudentBindingSource.Position = Form1.CurrRec

End Sub
End Class
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Please help!! I have already looked up the books from the bookstores and libraries but could not find any resources that can help.

Jason

Continue reading...
 

Similar threads

Back
Top