Skip to main content

AccessTr.neT


Excel Vba İle Userform Üzerinden Kayıt Silme Hakkında.

Oğuz Türkyılmaz
Oğuz Türkyılmaz
27
2251

Excel Vba İle Userform Üzerinden Kayıt Silme Hakkında.

#19
gerçi soru çözüldü ama farklı bir yöntem buldum onu da eklemek istedim
Not1: aslında her silmeden sonra firmaunvan açılır kutusu güncellenmeli
Not2: bu kadar az veriyle hızını kontrol edemedim hızla ilgili bilgi verirseniz sevinirim
Sub KytSil(ByVal IDBul As String)

Dim tbl As ListObject
Dim Sonuc As Range
Dim IDBul As String

With ThisWorkbook.Worksheets("ana_sayfa")
 
  Set tbl = .ListObjects("Tablo1")

'1. sütunda veri arama
  On Error Resume Next
  Set Sonuc = tbl.DataBodyRange.Columns(1).Find(IDBul, LookAt:=xlWhole)
  On Error GoTo 0

'bulunan verini silinmesi
        .Unprotect "171717"
            If Not Sonuc Is Nothing Then
              xTblBul = tbl.ListRows(Sonuc.row - tbl.HeaderRowRange.row).Index
              tbl.ListRows(xTblBul).Delete
            End If
        .Protect "171717"
End With
End Sub
.rar WINPERAX DENEMELER_hy7.rar (Dosya Boyutu: 188,25 KB | İndirme Sayısı: 1)
Cevapla
#20
kayıt silince combodan da o değeri silen kod eklenmiştir
ComboBox_FirmaUnvani.RemoveItem (Me.ComboBox_FirmaUnvani.ListIndex) '<== combodan değer silme
Private Sub btn_KayitSil_Click()
If Len(TextBox_ID & "") = 0 Then Exit Sub
If MsgBox("Veriler Silinecek, Emin misiniz...?", vbExclamation + vbYesNo, "Firma Tanımlama Formu") = vbNo Then Exit Sub

    With ThisWorkbook.Worksheets("Ana_Sayfa")
            KytSil (TextBox_ID)
            ComboBox_FirmaUnvani.RemoveItem (Me.ComboBox_FirmaUnvani.ListIndex) '<== combodan değer silme
            Call temizle
            TextBox_Tarih = Format(Date, "dd.mm.yyyy")
   
    End With
   
    TextBox_Tarih.SetFocus
       
    With TextBox_Tarih
                .SelStart = 0
                .SelLength = .TextLength
            End With
           
    btn_KayitEkle.Enabled = True
    
End Sub
Modüle eklenen kayıt silme kodu
Sub KytSil(ByVal IDBul As String)

Dim tbl As ListObject
Dim Sonuc As Range

With ThisWorkbook.Worksheets("ana_sayfa")
 
  Set tbl = .ListObjects("Tablo1")

'1. sütunda veri arama
  On Error Resume Next
  Set Sonuc = tbl.DataBodyRange.Columns(1).Find(IDBul, LookAt:=xlWhole)
  On Error GoTo 0

'bulunan verini silinmesi
        .Unprotect "171717"
            If Not Sonuc Is Nothing Then
              xTblBul = tbl.ListRows(Sonuc.row - tbl.HeaderRowRange.row).Index
              tbl.ListRows(xTblBul).Delete
            End If
        .Protect "171717"
End With
End Sub
.rar WINPERAX DENEMELER_hy8.rar (Dosya Boyutu: 190,24 KB | İndirme Sayısı: 1)
Cevapla
#21
Buda alternatif olsun dictionary ve dizi ile Img-grin

Private Sub btn_KayitSil_Click()
    Dim dic As Object, i As Long
    Dim dizi, sonTabloSatr As Long, aranan
   
    If Len(Trim(TextBox_ID.Value)) = 0 Then Exit Sub
    If Len(Trim(ComboBox_FirmaUnvani.Value)) = 0 Then Exit Sub
    If MsgBox("Veriler Silinecek, Emin misiniz...?", vbExclamation + vbYesNo, "Firma Tanýmlama Formu") = vbNo Then Exit Sub

    With ThisWorkbook.Worksheets("Ana_Sayfa")
        sonTabloSatr = .Cells.Find("*", _
                                    SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row
   
        If WorksheetFunction.CountA(.Range("A2:A" & Rows.Count)) = 0 Then Exit Sub
        If sonTabloSatr < 2 Then Exit Sub
        Set dic = CreateObject("scripting.dictionary")
        If WorksheetFunction.CountA(.Range("A2:A" & Rows.Count)) = 1 Then
            dic.Add CStr(.Range("A" & sonTabloSatr).Value), 2
        ElseIf WorksheetFunction.CountA(.Range("A2:A" & Rows.Count)) > 1 Then
            dizi = .Range("A2:A" & sonTabloSatr).Value
            For i = LBound(dizi) To UBound(dizi)
                aranan = CStr(dizi(i, 1))
                If dic.Exists(aranan) = False Then dic.Add aranan, i + 1
            Next
            Erase dizi
        End If
       
        If dic.Count = 0 Then Exit Sub
        .Unprotect "171717"
        .Rows(dic(CStr(Me.TextBox_ID.Value))).Delete
        UserForm_Initialize
        .Protect "171717"
        Call temizle
        TextBox_Tarih = Format(Date, "dd.mm.yyyy")
    End With
   
    TextBox_Tarih.SetFocus
       
    With TextBox_Tarih
                .SelStart = 0
                .SelLength = .TextLength
            End With
           
    btn_KayitEkle.Enabled = True
    Set dic = Nothing
    MsgBox "Kayit silindi..", vbInformation, "Bilgi"
End Sub
Cevapla
#22
Feraz Hocam Zahmet oldu size de ama anladım çok teşekkür ederin.
Access Çekirgesi 
[Resim: img-cray.gif]


Cevapla
#23
Berduş hocam teşekkür ederim bende bu sorunu me.requery ile çözmeye çalışıyordum. Img-grin

Kodların en son halini bu şekilde düzenledim. Sorunsuz çalışıyor. Feraz hocam la sizin kodların mixini yapmış oldum gibi oldu. Img-grin Hız konusunda ilerde bilgi verebilirim ancak. Kodların bu şekliyle kayıtları girmeye yeni başlıyorum. Yeterince kayıt girdikten sonra hızda bir yavaşlama algılarsam mutlaka sizin ve feraz hocamın yeni kodlarıyla da deneme yapar bilgi veririm.

Kod:
Private Sub btn_KayitSil_Click()

If ComboBox_FirmaUnvani.Tag = "" Or TextBox_ID.Value = "" Then
    MsgBox "Firma Ünvanları Seçeneğinden Silmek İstediğiniz Kaydı Seçmelisiniz...", vbCritical, "Hata"
    
    Exit Sub
    End If

If MsgBox("Veriler Silinecek, Emin misiniz...?", vbExclamation + vbYesNo, "Firma Tanımlama Formu") = vbNo Then Exit Sub
    
    With ThisWorkbook.Worksheets("Ana_Sayfa")
    .Unprotect "171717"
    .Rows(ComboBox_FirmaUnvani.Tag).EntireRow.Delete
     ComboBox_FirmaUnvani.RemoveItem (Me.ComboBox_FirmaUnvani.ListIndex)
     ComboBox_FirmaUnvani.Tag = ""
    .Protect "171717"
     Call temizle
     TextBox_Tarih = Format(Date, "dd.mm.yyyy")
    
        
    End With
    TextBox_Tarih.SetFocus
    With TextBox_Tarih
        .SelStart = 0
        .SelLength = .TextLength
    End With
    btn_KayitEkle.Enabled = True
    
End Sub

Access Çekirgesi 
[Resim: img-cray.gif]


Cevapla
#24
Hızda yavaşlama olmaz abey hiçbir kodda.
Cevapla

Bir hesap oluşturun veya yorum yapmak için giriş yapın

Yorum yapmak için üye olmanız gerekiyor

ya da
Task