Share via

Edit user Form

Anonymous
2022-08-24T22:06:13+00:00

Greetings,

I nearly have this completed. The User form works great for input, and deletion. The problem now is the edit, and it is only the date column. When I select my row on my form to edit the cells get populated but the Date Cell is incorrect. I provided my current macro. Columns 2 through 4 I know without a doubt are correct. Its is the first Column. I've been moving things around and still cannot get it to work. Any suggestions would be great. I originally had the line

Excel Formula:Me.date.Value = Me.lstactivity.List(Me.lstactivity.ListIndex, 1)

and everything shifted to the left on the form, so the weight column was blank. That is how I know it is the date I need to put right.

VBA Code:Private Sub cmdEdit_Click() If Selected_list = 0 Then

MsgBox "No row is selected.", vbOKOnly + vbInformation, "Edit"

Exit Sub
End If

Me.txtRowNumber.Value = Selected_list + 1

.Value = CDate(Me.Txtdate) = Me.lstactivity.List(Me.lstactivity.ListIndex, 1)
Me.Txtmission.Value = Me.lstactivity.List(Me.lstactivity.ListIndex, 2)
Me.Cmbmode.Value = Me.lstactivity.List(Me.lstactivity.ListIndex, 3)
Me.Cmbdenton_fms.Value = Me.lstactivity.List(Me.lstactivity.ListIndex, 4)
Me.Txtweight.Value = Me.lstactivity.List(Me.lstactivity.ListIndex, 5)
MsgBox "Please make the required changes and click on 'Save' button to update,", vbOKOnly + vbInformation, "Edit"

End Sub

Thank you so much!
Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2022-08-24T22:28:54+00:00

The line

.Value = CDate(Me.Txtdate) = Me.lstactivity.List(Me.lstactivity.ListIndex, 1)

has 2 equals symbols, that makes no sense. The original line was syntactically correct.

Keep in mind that the column index of a list box is zero-based, so List(..., 0) is the first column; List(..., 1) is the second column, etc.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2022-08-25T07:07:48+00:00

    You can use

    Me.txtdate.Value = Format(Me.lstactivity.List(Me.lstactivity.ListIndex, 0), "dd mmm yy")

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2022-08-24T23:04:01+00:00

    Outstanding, it would be nice to have the date come back in the dd mmm yy format in the form input box. It is okay, because a new date will be entered or simply retyped. I used Me.txtdate.Value = Me.lstactivity.List(Me.lstactivity.ListIndex, 0). At least I'm not erroring out.

    Much appreciated for your stellar knowledge and help.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2022-08-24T22:47:15+00:00

    I recognized that, surprised it didn't have the same numbers when I was inputting the numbers. I got it to take. But when rather than the date showing up in the "Date" input box, I got the Excel Date version like "44247". Strange how would I get it to read the proper date, or is it something I just have to live with?

    Thank you, at least I can follow some basic instructions.

    Much appreciated.

    Was this answer helpful?

    0 comments No comments