I'm basically trying to either mimic the BindingNavigatorAddNewItem button or utilize it.

Ideally I'd like to make my original code work.

The code for my on "Add New Ticket Button" click
simply clears the fields on my form and determines the next number to use for a TicketNum, and Places that new number in the TicketNum text box

After this the user would enter the information in the form and would click save to add the new information to the recordset

this is the code for the save button

If txtTicketNum.Text = (dsTickets.Tables("WorkTickets").Rows(MaxRows - 1).Item(0) + 1).ToString Then
        Dim dsNewRow As DataRow
        Dim dsNewDispatch As DataRow

        dsNewRow = dsTickets.Tables("WorkTickets").NewRow()

        'Worktickets table

        dsNewRow.Item("TicketNum") = (dsTickets.Tables("WorkTickets").Rows(MaxRows - 1).Item(0) + 1).ToString

        dsNewRow.Item("Priority") = txtPriority.Text
        dsNewRow.Item("DateIn") = dateIN.Value
        'If dateRequest.Value.ToString <> "1/1/1900 12:00:00 AM" Then
        'dsNewRow.Item("DateRequest") = dateRequest.Value
        'End If
        If dateOut.Value.ToString <> "1/1/1900 12:00:00 AM" Then
            dsNewRow.Item("DateOut") = dateOut.Value
        End If
        dsNewRow.Item("Category") = txtCategory.Text
        dsNewRow.Item("Description") = txtDescription.Text
        dsNewRow.Item("Resolution") = txtResolution.Text
        dsNewRow.Item("TicketStatus") = txtStatus.Text
        dsNewRow.Item("Location") = txtLocation.Text
        dsNewRow.Item("ContactName") = txtContact.Text
        dsNewRow.Item("ContactInfo") = txtContactInfo.Text


        'dispatch table
        If txtEmpNum.Text <> "" Then

            dsNewDispatch = dsTickets.Tables("Dispatch").NewRow
            dsNewDispatch.Item("EmployeeNum") = txtEmpNum.Text
            dsNewDispatch.Item("TicketNum") = txtTicketDispatch.Text

        End If
    End If

When I try to use the Save button, it simply updates whatever record I was viewing when I hit the Add New Record Button (with the exception of the Ticket number)

Alternatively I guess I could do something with


but I don't know how to control what number this button generates for my autonumber (primary key)

(Pressing the button generates a key of -1, where the first key I would want to generate would be 10 since the last entry in my database is numbered 9)

A Third option I can only guess might have something to do with bindingsources, but frankly I haven't a clue about how to manipulate them. All I have to go off is the code for the save (diskette) button on the binding navigator.


Maybe a better question to ask here is...

Why does my Autonumber generate a -1 when I click bindingnavigatoraddnewitem and then increment by -1 again on every additional click?

This article has been dead for over six months. Start a new discussion instead.