I need to add more columns in the filter box, now it gives an error to populate from the database
>>> use code - tags <<<
>>> use code - tags <<<
Code:
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Data")
Dim row_number As Long
Dim max_id As Long
max_id = Application.WorksheetFunction.Max(sh.Range("A:A"))
If Me.txt_id.Value = "" Then ''' Insert
row_number = Application.WorksheetFunction.CountA(sh.Range("A:A")) + 1
sh.Range("A" & row_number).Value = max_id + 1
Else '''' Update
row_number = Application.WorksheetFunction.Match(Int(Me.txt_id.Value), sh.Range("A:A"), 0)
End If
sh.Range("B" & row_number).Value = Me.txt_desc.Value
sh.Range("C" & row_number).Value = Me.cmb_Room.Value
sh.Range("D" & row_number).Value = Me.cmb_Ltype.Value
sh.Range("E" & row_number).Value = Me.txt_Open_Date.Value
sh.Range("F" & row_number).Value = Me.txt_openT.Value
sh.Range("G" & row_number).Value = Me.txt_Close_Date.Value
sh.Range("H" & row_number).Value = Me.cmb_staff.Value
sh.Range("I" & row_number).Value = Me.cmb_Department.Value
sh.Range("J" & row_number).Value = Me.cmb_Status.Value
sh.Range("K" & row_number).Value = Me.txt_Comments.Value
sh.Range("L" & row_number).Value = Me.cmb_inforstaff.Value
sh.Range("M" & row_number).Value = Me.txtName.Value
sh.Range("M" & row_number).Value = Me.txtName.Value
sh.Range("N" & row_number).Value = Me.cmb_nation.Value
sh.Range("O" & row_number).Value = Now
Call Reset_Form
MsgBox "Log is Updated", vbInformation
Call Refresh_Listbox
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'to populate listbox from Database sheet
Me.txt_id.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 0)
Me.txt_desc.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 1)
Me.cmb_Room.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 2)
Me.cmb_Ltype.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 3)
Me.txt_Open_Date.Value = Format(Me.ListBox1.List(Me.ListBox1.ListIndex, 4), "D-MMM-YYYY")
Me.txt_openT.Value = Format(Me.ListBox1.List(Me.ListBox1.ListIndex, 5), "HH:MM")
If Me.ListBox1.List(Me.ListBox1.ListIndex, 6) <> "" Then
Me.txt_Close_Date.Value = Format(Me.ListBox1.List(Me.ListBox1.ListIndex, 6), "D-MMM-YYYY")
End If
Me.cmb_staff.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 7)
Me.cmb_Department.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 8)
Me.cmb_Status.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 9)
Me.txt_Comments.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 10)
Me.cmb_inforstaff.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 11)
End Sub
Last edited by a moderator: