Trying to Edit Form, and the data is adding "6" and moving data around.

TVBurke_18

New Member
Joined
Jul 27, 2023
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
  2. Web
Here

1690486397422.png


Code for Edit Command Button:
Private Sub cmdEdit_Click()

If Selected_List = 0 Then

MsgBox "No Row is selected.", vbOKOnly + vbInformatiion, "Edit"

Exit Sub

End If

'Code to udpate the value to respective controls



Me.txtRowNumber.Value = Selected_List + 1

Me.txtVendorName.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 0)

Me.txtTaskNumber.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 1)

Me.cmbVendorType.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 2)

Me.cmbSetupType.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 3)

Me.txtVendorNumber.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 4)

Me.txtVendorDepartmentNumber.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 5)

Me.txtCreationDate.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 6)

Me.txtGoLiveDate.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 7)

Me.txtEDIProvider.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 8)

MsgBox "Please make your required changes and click 'Save' to update.", vbOKOnly + vbInformation, "Edit"


End Sub

USER FORM Code-

Private Sub cmdDelete_Click()

If Selected_List - 0 Then

MsgBox "No row is selected.", vbOKOnly + vbInformation, "Delete"
Exit Sub

End If

Dim i As VbMsgBoxResult

i = MsgBox("Do you want to delete selected record?", vbYesNo + vbQuestion, "Confirmation")

If i = vbNo Then Exit Sub

ThisWorkbook.Sheets("Database").Rows(Selected_List + 1).Delete

Call Reset

MsgBox "Selected Record has been deleted.", vbOKOnly + vbInformation, "Deleted"



End Sub

Private Sub cmdEdit_Click()

If Selected_List = 0 Then

MsgBox "No Row is selected.", vbOKOnly + vbInformatiion, "Edit"

Exit Sub

End If

'Code to udpate the value to respective controls



Me.txtRowNumber.Value = Selected_List + 1

Me.txtVendorName.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 0)

Me.txtTaskNumber.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 1)

Me.cmbVendorType.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 2)

Me.cmbSetupType.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 3)

Me.txtVendorNumber.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 4)

Me.txtVendorDepartmentNumber.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 5)

Me.txtCreationDate.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 6)

Me.txtGoLiveDate.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 7)

Me.txtEDIProvider.Value = Me.lstDatabase.List(Me.lstDatabase.ListIndex, 8)

MsgBox "Please make your required changes and click 'Save' to update.", vbOKOnly + vbInformation, "Edit"




End Sub

Private Sub cmdReset_Click()

Dim msgValue As VbMsgBoxResult

msgValue = MsgBox("Do you want to Reset the form?", vbYesNo + vbInformation, "Confirmation")

If msgValue = vbNo Then Exit Sub

Call Reset


End Sub

Private Sub cmdsave_Click()

Dim msgValue As VbMsgBoxResult

msgValue = MsgBox("Do you want to save the data?", vbYesNo + vbInformation, "Confirmation")

If msgValue = vbNo Then Exit Sub

Call Submit
Call Reset


End Sub


Private Sub CommandButton1_Click()

End Sub

Private Sub txtCreationDate_Change()

End Sub

Private Sub UserForm_Initialize()

Call Reset


End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
It's hard to be sure without seeing your data, but it appears as though you need to start incrementing this line:
VBA Code:
Me.lstDatabase.List(Me.lstDatabase.ListIndex, 0)
at 1 rather than 0
 
Upvote 0
Call Submit
Call Reset
You didn't post the code for those macros.

You must put all your code.

Also, I think you are using the Rowsource property to fill the listbox, but it is not in your code.

Could you share your file to help you with all the code.

You could upload a copy of your file to a free site such www.dropbox.com or google drive. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
I thought I copied all the code in the post. I apologize as I am very new to this. I tried to go to Drop Box, but my company laptop will not allow me to download it. Is there any other way I can try to share my excel document?

Also, when I click into the module I tried to copy all the code, and then I double clicked on each command button to copy that code, is that the incorrect way to do it?
 
Upvote 0
The problem is that I don't know how it's loading the data into the listbox and you don't say how it loads the data into the listbox.

First, you need to tell us how you load the data into the listbox.


Second, you should put all your code here.

Try the following, in the userform code.

1. Select the word "Submit"
1690556374785.png


2. From the View menu, choose Definition (SHIFT+F2).
1690557010118.png


3. That will get you the code for the "Submit" procedure, copy that code and paste it here.

4. Repeat the steps for the "Reset" procedure.


Please pay attention to all my instructions.

Note Code Tag:
In future please use code tags when posting code.
How to Post Your VBA Code it makes your code easier to read and copy and it also maintains VBA formatting.


Or try to share your file by google drive....
😅
 
Upvote 0
Sorry I don't want to waste your time. I don't know how to navigate as well as a seasoned person at this.
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,133
Members
449,098
Latest member
Doanvanhieu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top