I'm almost there.
I have a userform of many textbox. What I want to happen is to dont have any duplicate TIN. all data will be populated based on TIN. Now, all data will be added to worksheet name "DBPIT". You can retrieve the information back to userform by entering the TIN number. After which, I desired to edit the values on that certain TIN (TIN can't be edited, else a new TIN will be added). You can't also edit an information if its not yet added on the database. See my codes please...
Here is my code to paste everything to the worksheet "DBPIT"
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("DBPIT")
ws.Activate
If Trim(Me.txtTIN.Value) = "" Then
Me.txtTIN.SetFocus
MsgBox "Please enter the TIN"
Exit Sub
End If
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
If Application.WorksheetFunction.CountIf(Worksheets("DBPIT").Range("B:B"), txtTIN.Text) > 0 Then
MsgBox ("That order already exists on your database. If you want to update your order, click the Update Order Button")
Cancel = True
Else
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtDate.Value
ws.Cells(iRow, 2).Value = Me.txtTIN.Value
ws.Cells(iRow, 3).Value = Me.txtEntName.Value
ws.Cells(iRow, 4).Value = Me.txtAdd.Value
ws.Cells(iRow, 5).Value = Me.txtOM.Value
ws.Cells(iRow, 6).Value = Me.cboSvcType.Value
ws.Cells(iRow, 7).Value = Me.cboAccType.Value
ws.Cells(iRow, 8).Value = Me.txtCktID.Value
ws.Cells(iRow, 9).Value = Me.txtLinePort.Value
ws.Cells(iRow, 10).Value = Me.txtLocName.Value
ws.Cells(iRow, 11).Value = Me.txtLocID.Value
ws.Cells(iRow, 12).Value = Me.txtHubID.Value
ws.Cells(iRow, 13).Value = Me.txtDvcName.Value
ws.Cells(iRow, 14).Value = Me.txtNat.Value
ws.Cells(iRow, 15).Value = Me.txtOut.Value
ws.Cells(iRow, 16).Value = Me.txtDomain.Value
ws.Cells(iRow, 17).Value = Me.txtTN.Value
ws.Cells(iRow, 18).Value = Me.txtCsip1.Value
ws.Cells(iRow, 19).Value = Me.txtCssip1.Value
ws.Cells(iRow, 20).Value = Me.txtCssPort1.Value
ws.Cells(iRow, 21).Value = Me.txtCpe1a.Value
ws.Cells(iRow, 22).Value = Me.txtCpe2a.Value
ws.Cells(iRow, 23).Value = Me.txtCsFQDN1.Value
ws.Cells(iRow, 24).Value = Me.txtCsFQDN2.Value
ws.Cells(iRow, 25).Value = Me.txtCsip2.Value
ws.Cells(iRow, 26).Value = Me.txtCssip2.Value
ws.Cells(iRow, 27).Value = Me.txtCssPort2.Value
ws.Cells(iRow, 28).Value = Me.txtCpe1b.Value
ws.Cells(iRow, 29).Value = Me.txtCpe2b.Value
ws.Cells(iRow, 30).Value = Me.txtCktID2.Value
ws.Cells(iRow, 31).Value = Me.txtVPN.Value
ws.Cells(iRow, 32).Value = Me.txtRouter.Value
ws.Cells(iRow, 33).Value = Me.txtVRF.Value
ws.Cells(iRow, 34).Value = Me.txtPE.Value
ws.Cells(iRow, 35).Value = Me.txtCE.Value
ws.Cells(iRow, 36).Value = Me.txtVLAN.Value
ws.Cells(iRow, 37).Value = Me.txtSO.Value
ws.Cells(iRow, 38).Value = Me.txtTPSDate.Value
ws.Cells(iRow, 39).Value = Me.txtOVC.Value
ws.Cells(iRow, 40).Value = Me.txtPITDate.Value
ws.Cells(iRow, 41).Value = Me.txtISR.Value
ws.Cells(iRow, 42).Value = Me.txtLD.Value
ws.Cells(iRow, 43).Value = Me.txtLocal.Value
End If
ThisWorkbook.Save
End Sub
now, this is my code to edit the information that was already added.
Private Sub cmdUpdate_Click()
Dim Y As Long
If Application.WorksheetFunction.CountIf(Worksheets("DBPIT").Range("B:B"), txtTIN.Text) = 0 Then
MsgBox ("You can't update that order yet. Add it on the Database first.")
Cancel = True
Else
Y = Application.CountA(Sheets("DBPIT").Range("A:A"))
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 0).Value = txtDate.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 1).Value = txtTIN.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 2).Value = txtEntName.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 3).Value = txtAdd.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 4).Value = txtOM.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 5).Value = cboSvcType.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 6).Value = cboAccType.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 7).Value = txtCktID.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 8).Value = txtLinePort.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 9).Value = txtLocName.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 10).Value = txtLocID.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 11).Value = txtHubID.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 12).Value = txtDvcName.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 13).Value = txtNat.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 14).Value = txtOut.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 15).Value = txtDomain.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 16).Value = txtTN.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 17).Value = txtCsip1.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 18).Value = txtCssip1.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 19).Value = txtCssPort1.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 20).Value = txtCpe1a.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 21).Value = txtCpe2a.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 22).Value = txtCsFQDN1.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 23).Value = txtCsFQDN2.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 24).Value = txtCsip2.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 25).Value = txtCssip2.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 26).Value = txtCssPort2.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 27).Value = txtCpe1b.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 28).Value = txtCpe2b.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 29).Value = txtCktID2.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 30).Value = txtVPN.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 31).Value = txtRouter.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 32).Value = txtVRF.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 33).Value = txtPE.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 34).Value = txtCE.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 35).Value = txtVLAN.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 36).Value = txtSO.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 37).Value = txtTPSDate.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 38).Value = txtOVC.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 39).Value = txtPITDate.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 40).Value = txtISR.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 41).Value = txtLD.Text
Worksheets("DBPIT").Range("A:A").End(xlUp).Offset(Y, 42).Value = txtLocal.Text
End If
End Sub
now, the problem is, everytime I pull up information based on TIN and then edit some of the information, it will be added at the last row but will not edit the existing data.
Please help. Thank you. Please see attached file.
Bookmarks