Hello friends, I would like to seek some help here, I have a user form with Listbox, I want to show on the top of the listbox the new data , when he hit the command button submit.
Here are my code, can someone can modify?
Thanks in advance
-Module
Sub Submit()
Dim Sh As Worksheet
Dim iRow As Long
Set Sh = ThisWorkbook.Sheets("Database")
iRow = [Counta(Database!A:A)] + 1
With Sh
.Cells(iRow, 1) = iRow - 1
.Cells(iRow, 2) = frmForm.txtName.Value
.Cells(iRow, 3) = frmForm.txtID.Value
.Cells(iRow, 4) = [Text(Now(),"YYYY-MM-DD HH:MM:SS")
End With
End Sub
Private Sub cmdSubmit_Click()
Dim msgvalue As VbMsgBoxResult
msgvalue = MsgBox("Do you want to save the data?", vbYesNo + vbInformation, "Confirmation")
If msgvalue = vbNo Then Exit Sub
If txtName.Value = "" Or txtID.Value = "" Then
If msgvalue = MsgBox("Data not complete!", vbYesNo + vbQuestion + vbYesNo) <> vbYes Then
Exit Sub
End If
End If
txtName.SetFocus
With Me.lstDatabase
.RowSource = .RowSource 'Forces update if data added or deleted from Data range after Userform is shown
.Selected(.ListCount - 1) = True 'Selects newentry item in the ListBox
End With
Call Submit
Call Reset
End Sub
Here are my code, can someone can modify?
Thanks in advance
-Module
Sub Submit()
Dim Sh As Worksheet
Dim iRow As Long
Set Sh = ThisWorkbook.Sheets("Database")
iRow = [Counta(Database!A:A)] + 1
With Sh
.Cells(iRow, 1) = iRow - 1
.Cells(iRow, 2) = frmForm.txtName.Value
.Cells(iRow, 3) = frmForm.txtID.Value
.Cells(iRow, 4) = [Text(Now(),"YYYY-MM-DD HH:MM:SS")
End With
End Sub
Private Sub cmdSubmit_Click()
Dim msgvalue As VbMsgBoxResult
msgvalue = MsgBox("Do you want to save the data?", vbYesNo + vbInformation, "Confirmation")
If msgvalue = vbNo Then Exit Sub
If txtName.Value = "" Or txtID.Value = "" Then
If msgvalue = MsgBox("Data not complete!", vbYesNo + vbQuestion + vbYesNo) <> vbYes Then
Exit Sub
End If
End If
txtName.SetFocus
With Me.lstDatabase
.RowSource = .RowSource 'Forces update if data added or deleted from Data range after Userform is shown
.Selected(.ListCount - 1) = True 'Selects newentry item in the ListBox
End With
Call Submit
Call Reset
End Sub
Attachments
Last edited: