0
Public Class Form1
    Private ContactsTableBindingSource As Object

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'ContactsTableDataSet.Table' table. You can move, or remove it, as needed.
        Me.TableTableAdapter.Fill(Me.ContactsTableDataSet.Table)
        If ComboBox1.Text = Nothing Then
            Try
                ContactsTableBindingSource.AddNew()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If First_NameTextBox.Text = Nothing Then
            First_NameTextBox.Text = "unknown"
        End If
        If Last_NameTextBox.Text = Nothing Then
            Last_NameTextBox.Text = "unknown"
        End If
        If AddressTextBox.Text = Nothing Then
            AddressTextBox.Text = "unknown"
        End If
        If Phone_NumberTextBox.Text = Nothing Then
            Phone_NumberTextBox.Text = "unknown"
        End If
        If Email_AddressTextBox.Text = Nothing Then
            Email_AddressTextBox.Text = "unknown"
        End If
        Try
            Me.Validate()
            Me.ContactsTableBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.ContactsTableDataSet)
            MessageBox.Show("The data has been saved", "Information", MessageBoxButtons.OK)
            ContactsTableBindingSource.AddNew()
            First_NameTextBox.Select()
        Catch ex As Exception
            MessageBox.Show(ex.Message)

        End Try
    End Sub

Please suggest a correction in the code as I have being showing the error "object variable or Withblock not set"

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
  • 2
    Start by turning on Option Strict. I am not clear what the deal is. That is a VB6 error message, but the code is VB.NET. ALso it would be nice to know where the error happens. Please read [ask] and take the [tour] – Ňɏssa Pøngjǣrdenlarp Jan 01 '17 at 11:24
  • Did you read [Object variable or With block variable not set](https://msdn.microsoft.com/en-us/library/5szkzs17.aspx) in MSDN? – Anton Samsonov Jan 01 '17 at 11:26

0 Answers0