• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

Kayıt Sonrası ListBox Yenileme

Katılım
16 Eylül 2010
Mesajlar
34
Excel Vers. ve Dili
2007
Merhaba..
UserForm1 ve UserForm2 olarak 2 adet form var.
UserForm1'de tablodan çekilen veriler var. (Listbox1)
UserForm2'de veri ekleme formu var.

Sorun şu ki UserForm2'de kayıt yaptığım zaman kaydet dediğimde;
"MsgBox "KAYIT YAPILDI", vbOKOnly + vbInformation, "Veri Kaydedildi"
"Unload Me"

mesajı verilip userForm2 kapandığında UserForm1'de bulunan ListBox1'de son yapılan kayıt görünmüyor. Kaydı görebilmek için tekrar başlatmak gerekiyor.
UserForm1'deki Listbox1'i kayıt sonrası nasıl yenileyebilirim?
 
UserForm 1 açıldığında listboxa veriler nasıl ekleniyorsa UserForm2 de Kaydet butonuna bastıktan sonra aynı şekilde yenilemek sorununuzu çözecektir.

Eğer yapamazsanız dosyanızı ekleyin biz yapalım.
 
Kod:
Private Sub cmdbuttom_kaydet_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Data")

'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).row + 1

'check for a Name number
If Trim(Me.TextBox1.Value) = "" Then
  Me.TextBox1.SetFocus
  MsgBox "Lütfen Formu Doldurun"
  Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.TextBox1.Value
ws.Cells(iRow, 2).Value = Me.TextBox2.Value
ws.Cells(iRow, 3).Value = Me.TextBox3.Value

MsgBox "KAYIT YAPILDI", vbOKOnly + vbInformation, "Veri Kaydedildi"
'clear the data
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""

Unload Me
End Sub

Private Sub CommandButton2_Click()
Unload Me
End Sub

Private Sub TextBox2_Change()
TextBox2.Value = UCase(TextBox2.Value)
End Sub

Private Sub TextBox3_Change()
TextBox3.Value = UCase(TextBox3.Value)
End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()

Call RemoveCaption(Me)

TextBox2.SetFocus


TextBox1 = Worksheets("Data").Cells(Rows.Count, "A").End(3).row
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
   If CloseMode = vbFormControlMenu Then Cancel = True
End Sub
 
UserForm1 in initialize olayındaki kodları da ekleyin.
 
Kod:
Private Sub UserForm_Initialize()

Call RemoveCaption(Me)

TextBox13.SetFocus

ListBox1.ColumnWidths = "35;110;60"        'COLUMN WITH OF LISTBOX
ListBox1.ColumnCount = 3                   'COLUMN NUMBER OF LISTBOX
ListBox1.List = Sheets("Data").Range("a2:l" & [a65536].End(3).row).Value

'** SEARCH COMBOBOX
ComboBox1.AddItem "Ad"
ComboBox1.AddItem "Sıra"
ComboBox1.AddItem "Not"

'**********************************************

TextBox14.Value = ListBox1.ListCount
TextBox15.Value = 0
With lblDone ' set the "progress bar" to it's initial length
        .Top = lblRemain.Top + 1
        .Left = lblRemain.Left + 1
        .Height = lblRemain.Height - 2
        .Width = 0
    End With
lblPct.Visible = False

End Sub
 
Kaydet butonunun kodlarını aşağıdaki ile değiştirin.
Kod:
Private Sub cmdbuttom_kaydet_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Data")

'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).row + 1

'check for a Name number
If Trim(Me.TextBox1.Value) = "" Then
  Me.TextBox1.SetFocus
  MsgBox "Lütfen Formu Doldurun"
  Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.TextBox1.Value
ws.Cells(iRow, 2).Value = Me.TextBox2.Value
ws.Cells(iRow, 3).Value = Me.TextBox3.Value

MsgBox "KAYIT YAPILDI", vbOKOnly + vbInformation, "Veri Kaydedildi"
'clear the data
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""

Unload Me
userform1.ListBox1.List = Sheets("Data").Range("a2:l" & [a65536].End(3).row).Value
End Sub
 
Geri
Üst