|
-
Jan 15th, 2021, 06:33 PM
#1
Thread Starter
Junior Member
I'm typing in a textbox linked to a database and it stops everything from working.
So I am using a Data Set to insert items into my Microsoft Access Database, but whenever I type in the "CustomerID" Textbox, I am then prevented from doing anything, buttons won't work, Even the windows close form button gets disabled.
Code:
Option Explicit On
Option Strict Off
Public Class ManagePodBookings
Private Sub ManagePodBookings_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Loads the Pod Booking Database
RefreshData()
Me.PodBookingsTableAdapter.Fill(Me.PodBookingsDataSet.PodBookings)
End Sub
Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
'Shows the staff form
Staff.Show()
Me.Hide()
End Sub
Private Sub btnMainMenu_Click(sender As Object, e As EventArgs) Handles btnMainMenu.Click
'shows the main menu
MainMenu.Show()
Me.Hide()
End Sub
Private Sub PodComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles PodComboBox.SelectedIndexChanged
'Making it so users cannot edit ComboBox values
PodComboBox.DropDownStyle = ComboBoxStyle.DropDownList
End Sub
'Making it so users cannot edit ComboBox values
Private Sub RefreshData()
'Refreshing the table data
Try
Me.PodBookingsBindingSource.Filter = Nothing
Me.PodBookingsTableAdapter.Fill(Me.PodBookingsDataSet.PodBookings)
Catch ex As Exception
MsgBox("There was an error refreshing the data.")
End Try
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
'Adds a New Record within the Data Table.
Try
With btnAdd
If .Text = "Add New Record" Then
PodBookingsBindingSource.AddNew()
PeopleNumericUpDown.Value = 0
ArrivalDateDateTimePicker.Value = Now.Date
DepartureDateDateTimePicker.Value = Now.Date
.Text = "Cancel New Record"
Else
RefreshData()
.Text = "Add New Record"
End If
End With
Catch ex As Exception
MsgBox("There was an error adding a new record." & ex.Message.ToString(),
MsgBoxStyle.OkOnly Or MsgBoxStyle.Information)
End Try
End Sub
Private Sub Save_Click(sender As Object, e As EventArgs) Handles btnSave.Click
'Handles the save button
Try
Dim result As DialogResult
result = MessageBox.Show("Do you want to save the selected record?",
"Glorious Getaways", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If (result = DialogResult.Yes) Then
Validate()
PodBookingsBindingSource.EndEdit()
TableAdapterManager.UpdateAll(Me.PodBookingsDataSet)
MessageBox.Show("The record has been saved successfully.",
"Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Information)
RefreshData()
btnAdd.Text = "Add New Record"
Else
Return
End If
Catch ex As Exception
MessageBox.Show("There was an error Saving the Data." & ex.Message.ToString(),
"Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Delete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
'Deletes a record from the Data Table
Try
If MessageBox.Show("Do you want to permanently delete the selected record?",
"Glorious Getaways", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) =
Windows.Forms.DialogResult.Yes Then
PodBookingsBindingSource.RemoveCurrent()
PodBookingsBindingSource.EndEdit()
PodBookingsTableAdapter.Update(PodBookingsDataSet.PodBookings)
RefreshData()
MessageBox.Show("The record has been deleted sucessfully.",
"Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Return ' Exit Sub
End If
Catch ex As Exception
MessageBox.Show("There was an error deleting the Data." & ex.Message.ToString(),
"Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub SearchWarning()
'Disabling search whilst adding new record.
MsgBox("You are unable to Search whilst adding a new Record.",
MsgBoxStyle.OkOnly Or MsgBoxStyle.Exclamation,
"Glorious Getaways")
End Sub
Private Sub SearchBox_Click(sender As Object, e As EventArgs) Handles Search.Click, btnSearch.Click
'Disabling search whilst adding new record.
If btnAdd.Text = "Cancel New Record" Then
SearchWarning()
Exit Sub
End If
End Sub
Private Sub SearchButton_Click(search As Object, e As EventArgs) Handles btnSearch.Click
If PodBookingsBindingSource.Count < 1 Then
MsgBox("The search item was not found.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information,
"Glorious Getaways")
RefreshData()
End If
Try
Catch ex As Exception
MessageBox.Show("There was an error when Searching." & ex.Message.ToString(),
"Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs)
Try
Me.PodBookingsTableAdapter.FillBy(Me.PodBookingsDataSet.PodBookings)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
End Class
This is the code I have used, I'm currently working on a search button to search the database for specific strings inputted into a search text box.
Last edited by THopwood; Jan 16th, 2021 at 02:19 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|