ok
il form1:
Private Sub Button1_Click( sender As Object, e As EventArgs) Handles Button1.Click
My.Forms.Database_Win.Show()
End Sub
form2:
Public Class Database_Win
Private Sub Database_Win_Load( sender As Object, e As EventArgs) Handles MyBase.Load
If My.Computer.FileSystem.FileExists("C:\Users\....ac cdb") Then
MsgBox(" Database found ", MsgBoxStyle.Information, " Information ")
Else
Try
MsgBox(" Database not found ", MsgBoxStyle.Exclamation, " Attention ")
My.Computer.FileSystem.CopyFile(
"C:\Users\....accdb",
"C:\Users\....accdb")
' db back up is upload
MsgBox(" Loaded database ", MsgBoxStyle.Information, " Information ")
Catch ex As Exception
MsgBox(" The database doesn't exist or can't be loaded ", MsgBoxStyle.Critical, " Attention ")
Me.Close()
End Try
End If
Me.Table1TableAdapter.Fill(Me.VbAccess2007DataSet. Table1)
With DataGridView1
.ClearSelection()
.ReadOnly = True
.Multiselect = False
End With
Me.reset()
End Sub
' Previous btn
Public Sub Previous_btn_Click( sender As Object, e As EventArgs) Handles Previous_btn.Click
Table1BindingSource.MovePrevious()
End Sub
' Add New btn
Public Sub AddNew_btn_Click( sender As Object, e As EventArgs) Handles AddNew_btn.Click
Table1BindingSource.AddNew()
End Sub
' Next btn
Public Sub Next_btn_Click( sender As Object, e As EventArgs) Handles Next_btn.Click
Table1BindingSource.MoveNext()
End Sub
' Save btn
Public Sub Save_btn_Click( sender As Object, e As EventArgs) Handles Save_btn.Click
Try
' On Error Goto SaveErr
Table1BindingSource.EndEdit()
Table1TableAdapter.Update(VbAccess2007DataSet.Tabl e1)
MsgBox(" Save OK ", MsgBoxStyle.Information, " Information ")
Catch ex As Exception
MsgBox(" Don't Save ", MsgBoxStyle.Exclamation, " Information ")
End Try
End Sub
' Delete btn
Public Sub Delete_btn_Click( sender As Object, e As EventArgs) Handles Delete_btn.Click
If Table1BindingSource.Count <> 0 Then
If MsgBox(" Are you sure to delete ? ", MessageBoxButtons.YesNo + MsgBoxStyle.Exclamation, " Delete record ") = DialogResult.Yes Then
Table1BindingSource.RemoveCurrent
Else
Exit sub
End If
Else
MsgBox(" Delete isn't possibile because there aren't records ", MsgBoxStyle.Information, " Information ")
Exit sub
End If
End Sub
' Close btn
Public Sub Close_btn_Click( sender As Object, e As EventArgs) Handles Close_btn.Click
If MsgBox(" Are you sure to Exit ? ", MessageBoxButtons.YesNo + MsgBoxStyle.Question, " Exit database ") = DialogResult.Yes Then
End
End If
End Sub
' Update btn
Public Sub Update_btn_Click( sender As Object, e As EventArgs) Handles Update_btn.Click
Try
Table1BindingSource.EndEdit()
Table1TableAdapter.Update(VbAccess2007DataSet.Tabl e1)
MsgBox(" Update OK ", MsgBoxStyle.Information, " Information ")
Catch ex As Exception
MsgBox(" Don't Update ", MsgBoxStyle.Exclamation, " Information ")
End Try
End Sub
' Search btn
Public Sub Search_btn_Click( sender As Object, e As EventArgs) Handles Search_btn.Click
On Error Goto SearchErr
If txtSearch.Text = "" then
Call notFound()
Exit Sub
Else
Dim cantFind As String = txtSearch.Text
Me.dvgFill()
Table1BindingSource.Filter = "(Convert(ID, 'System.String') LIKE '" & txtSearch.Text & "')" & _
"OR (Stocknum LIKE '" & txtSearch.Text & "')" & _
"OR (Serialnum LIKE '" & txtSearch.Text & "')" & _
"OR (Convert(Testcellnum, 'System.String') LIKE '" & txtSearch.Text & "')"
If Table1BindingSource.Count <> 0 Then
With DataGridView1
.DataSource = Table1BindingSource
End With
Else
Me.notFound()
MsgBox("--> " & cantFind & vbNewLine & " The search item was not found. ", MsgBoxStyle.Information, " Error! ")
Table1BindingSource.Filter = Nothing
With DataGridView1
.ClearSelection()
.ReadOnly = True
.MultiSelect = False
.DataSource = Table1BindingSource
End With
End If
End If
ErrExit:
Exit Sub
SearchErr:
MsgBox(" Error Number " & Err.Number & vbNewLine & " Error Description " _
& Err.Description, MsgBoxStyle.Critical, " Reset Error! ")
Resume ErrExit
End Sub
' Reset function
Public Sub reset()
Dim txts As TextBox = txtSearch
With txtSearch
.Text = ""
.Select()
End With
If DataGridView1.DataSource is Nothing Then
Exit Sub
End If
End Sub
' notFound function
Public Sub notFound()
Dim txtS As TextBox = txtSearch
With txtS
.Select()
.SelectAll()
End With
If DataGridView1.DataSource is Nothing Then
Exit Sub
End If
End Sub
End Class

Rispondi quotando