Sharid
Well-known Member
- Joined
- Apr 22, 2007
- Messages
- 1,066
- Office Version
- 2016
- Platform
- Windows
I have as spreadsheet that shows its data in a userform listbox, when the data is selected from the listbox and the edit button is clicked it opens up a second userform CustEditForm and populates the texboxes. This bit is fine
This is the code that does this
The second userform has a submit button, but i can't workout the code to update the data without creating a extra record in my worksheet called CustDetails . I am not creating a new record, only updating exsisting records.
I've been stuck on this for a few weeks now. could someone please have a look
Thanks
This is the code that does this
Code:
Private Sub CommandButton2_Click()
'Yes/No Message Box
Dim YesOrNoAnswerToMessageBox As String
Dim QuestionToMessageBox As String
QuestionToMessageBox = "Are you sure you want to edit this Customer Record?"
YesOrNoAnswerToMessageBox = MsgBox(QuestionToMessageBox, vbYesNo, "Add New Products")
If YesOrNoAnswerToMessageBox = vbYes Then
'Loadsform with data
Load CustEditForm
With CustEditForm
.DateTB.Text = ListBox1.List(ListBox1.ListIndex, 1)
.IDTB.Text = ListBox1.List(ListBox1.ListIndex, 1)
.BusNameTB.Text = ListBox1.List(ListBox1.ListIndex, 2)
.NameContactTB.Text = ListBox1.List(ListBox1.ListIndex, 3)
.AddressNoTB.Text = ListBox1.List(ListBox1.ListIndex, 4)
.StreetTB.Text = ListBox1.List(ListBox1.ListIndex, 5)
.AreaTB.Text = ListBox1.List(ListBox1.ListIndex, 6)
.CityTB.Text = ListBox1.List(ListBox1.ListIndex, 7)
.PostCodeTB.Text = ListBox1.List(ListBox1.ListIndex, 8)
.TelephoneTB.Text = ListBox1.List(ListBox1.ListIndex, 9)
.MobileTB.Text = ListBox1.List(ListBox1.ListIndex, 10)
.FaxTB.Text = ListBox1.List(ListBox1.ListIndex, 11)
.EmailTB.Text = ListBox1.List(ListBox1.ListIndex, 12)
ListBox1.List(ListBox1.ListIndex, 1) = CustEditForm.DateTB.Text
ListBox1.List(ListBox1.ListIndex, 2) = CustEditForm.IDTB.Text
ListBox1.List(ListBox1.ListIndex, 3) = CustEditForm.BusNameTB.Text
ListBox1.List(ListBox1.ListIndex, 4) = CustEditForm.NameContactTB.Text
ListBox1.List(ListBox1.ListIndex, 5) = CustEditForm.AddressNoTB.Text
ListBox1.List(ListBox1.ListIndex, 6) = CustEditForm.StreetTB.Text
ListBox1.List(ListBox1.ListIndex, 7) = CustEditForm.AreaTB.Text
ListBox1.List(ListBox1.ListIndex, 8) = CustEditForm.CityTB.Text
ListBox1.List(ListBox1.ListIndex, 9) = CustEditForm.PostCodeTB.Text
ListBox1.List(ListBox1.ListIndex, 10) = CustEditForm.TelephoneTB.Text
ListBox1.List(ListBox1.ListIndex, 11) = CustEditForm.MobileTB.Text
ListBox1.List(ListBox1.ListIndex, 12) = CustEditForm.FaxTB.Text
End With
CustList.Hide
End If
End Sub
The second userform has a submit button, but i can't workout the code to update the data without creating a extra record in my worksheet called CustDetails . I am not creating a new record, only updating exsisting records.
I've been stuck on this for a few weeks now. could someone please have a look
Thanks
Last edited: