Hello All,
Everything is working well except the Edit macro. I am writing the macros per this youtube instructions and substituting with my fields.
This is the error message I get when the Edit Macro is ran:
Here is the Edit Macro.
Here is all the form's code if this is helpful:
Here is the Module code:
Thank you very much,
Tony
Everything is working well except the Edit macro. I am writing the macros per this youtube instructions and substituting with my fields.
This is the error message I get when the Edit Macro is ran:
Here is the Edit Macro.
VBA Code:
Private Sub cmdEdit_Click()
If Selected_List = 0 Then
MsgBox "No row is selected.", vbOKOnly + vbInformation, "Edit"
Exit Sub
End If
'Code to update the value to respective controls
Dim sPR As String
Me.txtRowNumber.Value = Selected_List + 1
Me.txtnumber.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 1)
Me.Txttitle.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 2)
Me.lbsystem.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 3)
sPR = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 4)
If sPR = "Y" Then
Me.optyes.Value = True
Else
Me.optno.Value = True
End If
Me.lbdefectcode.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 5)
Me.lbexpected.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 6)
Me.lbactual.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 7)
Me.txtproblem.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 8)
Me.txtnotes.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 9)
MsgBox "Please make the required changes and click on 'Save' button to update.", vbOKOnly + vbInformation, "Edit"
End Sub
Here is all the form's code if this is helpful:
VBA Code:
Option Explicit
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 the 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 + vbInformation, "Edit"
Exit Sub
End If
'Code to update the value to respective controls
Dim sPR As String
Me.txtRowNumber.Value = Selected_List + 1
Me.txtnumber.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 1)
Me.Txttitle.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 2)
Me.lbsystem.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 3)
sPR = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 4)
If sPR = "Y" Then
Me.optyes.Value = True
Else
Me.optno.Value = True
End If
Me.lbdefectcode.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 5)
Me.lbexpected.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 6)
Me.lbactual.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 7)
Me.txtproblem.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 8)
Me.txtnotes.Value = Me.lbdatabase.List(Me.lbdatabase.ListIndex, 9)
MsgBox "Please make the required changes and click on 'Save' button to update.", vbOKOnly + vbInformation, "Edit"
End Sub
Private Sub cmdreset_Click()
Dim msgValue As VbMsgBoxResult
msgValue = MsgBox("Do you want to rerest 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("Please check you entries and confirm you want to save the data", vbYesNo + vbInformation, "Confirmation")
If msgValue = vbNo Then Exit Sub
Call Submit
Call Reset
End Sub
Private Sub Frame1_Click()
End Sub
Private Sub UserForm_Initialize()
Call Reset
End Sub
Here is the Module code:
VBA Code:
Option Explicit
Sub Reset()
Dim iRow As Long
iRow = [Counta(Database!A:A)] 'identifying the last row'
With frmform1
.txtnumber.Value = " "
.Txttitle.Value = " "
.lbsystem.Clear
.lbsystem.AddItem "ACS"
.lbsystem.AddItem "Archive Data"
.lbsystem.AddItem "ATDS"
.lbsystem.AddItem "Autocapture Testbed"
.lbsystem.AddItem "AVN"
.lbsystem.AddItem "C&DH"
.lbsystem.AddItem "CBS"
.lbsystem.AddItem "COMLIDAR"
.lbsystem.AddItem "COMM"
.lbsystem.AddItem "COMSEC"
.lbsystem.AddItem "EGSE"
.lbsystem.AddItem "EGSE (Flight I&T)"
.lbsystem.AddItem "EPS"
.lbsystem.AddItem "FlatSat"
.lbsystem.AddItem "FSW"
.lbsystem.AddItem "HFCS"
.lbsystem.AddItem "L7 Mockups (Flight I&T)"
.lbsystem.AddItem "Landsat 7"
.lbsystem.AddItem "LIDAR"
.lbsystem.AddItem "MECH"
.lbsystem.AddItem "MGSE (Flight I&T)"
.lbsystem.AddItem "PCC"
.lbsystem.AddItem "PROP"
.lbsystem.AddItem "PSU"
.lbsystem.AddItem "PTS"
.lbsystem.AddItem "RDT"
.lbsystem.AddItem "REU"
.lbsystem.AddItem "ROBOT"
.lbsystem.AddItem "RPO"
.lbsystem.AddItem "RPO Testbed"
.lbsystem.AddItem "SC"
.lbsystem.AddItem "SCTHRM"
.lbsystem.AddItem "Servicing Payload (PYLD)"
.lbsystem.AddItem "Serviving Testbed"
.lbsystem.AddItem "Simulators"
.lbsystem.AddItem "SP/SV/SC SPIDER GSE"
.lbsystem.AddItem "Spave Vehicle Management"
.lbsystem.AddItem "SPIDER"
.lbsystem.AddItem "SPINT"
.lbsystem.AddItem "STR"
.lbsystem.AddItem "SVINT"
.lbsystem.AddItem "Testbeds"
.lbsystem.AddItem "THRM"
.lbsystem.AddItem "TOOL"
.lbsystem.AddItem "VDSU"
.lbsystem.AddItem "VSS"
.optyes.Value = False
.optno.Value = False
.lbdefectcode.Clear
.lbdefectcode.AddItem "10 - Solder Defect"
.lbdefectcode.AddItem "20 - Contamination"
.lbdefectcode.AddItem "30 - Shrink Tubing Missing"
.lbdefectcode.AddItem "40 - Not Built to Specification/Drawing"
.lbdefectcode.AddItem "50 - Dimensions Out of Tolerance"
.lbdefectcode.AddItem "60 - Failed Test"
.lbdefectcode.AddItem "70 - Accept"
.lbdefectcode.AddItem "80 - Damaged"
.lbdefectcode.AddItem "90 - Documentation Error"
.lbexpected.Clear
.lbexpected.AddItem ".5"
.lbexpected.AddItem "1"
.lbexpected.AddItem "1.5"
.lbexpected.AddItem "2"
.lbexpected.AddItem "2.5"
.lbexpected.AddItem "3"
.lbexpected.AddItem "3.5"
.lbexpected.AddItem "4"
.lbexpected.AddItem "4.5"
.lbexpected.AddItem "5"
.lbexpected.AddItem "5.5"
.lbexpected.AddItem "6"
.lbexpected.AddItem "6.5"
.lbexpected.AddItem "7"
.lbexpected.AddItem "7.5"
.lbexpected.AddItem "8"
.lbexpected.AddItem "8.5"
.lbexpected.AddItem "9"
.lbexpected.AddItem "9.5"
.lbexpected.AddItem "10"
.lbexpected.AddItem "10.5"
.lbexpected.AddItem "11"
.lbexpected.AddItem "11.5"
.lbexpected.AddItem "12"
.lbactual.Clear
.lbactual.AddItem ".5"
.lbactual.AddItem "1"
.lbactual.AddItem "1.5"
.lbactual.AddItem "2"
.lbactual.AddItem "2.5"
.lbactual.AddItem "3"
.lbactual.AddItem "3.5"
.lbactual.AddItem "4"
.lbactual.AddItem "4.5"
.lbactual.AddItem "5"
.lbactual.AddItem "5.5"
.lbactual.AddItem "6"
.lbactual.AddItem "6.5"
.lbactual.AddItem "7"
.lbactual.AddItem "7.5"
.lbactual.AddItem "8"
.lbactual.AddItem "8.5"
.lbactual.AddItem "9"
.lbactual.AddItem "9.5"
.lbactual.AddItem "10"
.lbactual.AddItem "10.5"
.lbactual.AddItem "11"
.lbactual.AddItem "11.5"
.lbactual.AddItem "12"
.txtproblem.Value = " "
.txtnotes.Value = " "
.txtRowNumber.Value = " "
.lbdatabase.ColumnCount = 12
.lbdatabase.ColumnHeads = True
.lbdatabase.ColumnWidths = "40,40,40,40,20,20,40,40,40,40,40,40"
If iRow > 1 Then
.lbdatabase.RowSource = "Database!A2:L" & iRow
Else
.lbdatabase.RowSource = "Database!A2:L2"
End If
End With
End Sub
Sub Submit()
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("Database")
If frmform1.txtRowNumber.Value = " " Then
iRow = [Counta(Database!A:A)] + 1
Else
iRow = frmform1.txtRowNumber.Value
End If
With sh
.Cells(iRow, 1) = iRow - 1
.Cells(iRow, 2) = frmform1.txtnumber.Value
.Cells(iRow, 3) = frmform1.Txttitle.Value
.Cells(iRow, 4) = frmform1.lbsystem.Value
.Cells(iRow, 5) = IIf(frmform1.optyes.Value = True, "Y", "N")
.Cells(iRow, 6) = frmform1.lbdefectcode.Value
.Cells(iRow, 7) = frmform1.lbexpected.Value
.Cells(iRow, 8) = frmform1.lbactual.Value
.Cells(iRow, 9) = frmform1.txtproblem.Value
.Cells(iRow, 10) = frmform1.txtnotes.Value
.Cells(iRow, 11) = Application.UserName
.Cells(iRow, 12) = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
End With
End Sub
Sub Show_Form()
frmform1.Show
End Sub
Function Selected_List() As Long
Dim i As Long
Selected_List = 0
For i = 0 To frmform1.lbdatabase.ListCount - 1
If frmform1.lbdatabase.Selected(i) = True Then
Selected_List = i + 1
Exit For
End If
Next i
End Function
Thank you very much,
Tony