Bill Williamson
Board Regular
- Joined
- Oct 7, 2019
- Messages
- 124
Just a little info, This is from a working userform, it had 3 text box's 6 combo box's and 6 check box's.
All the data went in same row, all columns next to each other. Ex. A1 - A15
This Sub does one of two things. It can Add a record, witch takes the info from userform saves it to worksheet.
Or get a record, that populates the userform with data from a row in the worksheet.
I need to modify it to work with a different form, but to do so I want to understand it.
Am I close?
thanks Bill
All the data went in same row, all columns next to each other. Ex. A1 - A15
This Sub does one of two things. It can Add a record, witch takes the info from userform saves it to worksheet.
Or get a record, that populates the userform with data from a row in the worksheet.
I need to modify it to work with a different form, but to do so I want to understand it.
VBA Code:
Sub AddGetRecord(ByVal Action As XLRecordActionType)
Dim i As Integer
Dim ControlsArr As Variant
ControlsArr = FormControls
If Action = xlAddRecord Then RecordRow = WorksheetFunction.CountA(wsData.Range("A:A")) ' Obviously this is part of the Add Record, I Think it is basically saying go ' to the end of the date colum A , and this is where the data is going to the worksheet
For i = 1 To 15 ' This cycles through the 15 Controls
With Me.Controls(ControlsArr(i))
If i < 10 Then ' I dont understand what this is for
If Action = xlGetRecord Then
.Text = wsData.Cells(RecordRow, i).Value 'I believe this gets the information from the worksheet and populates the 3 text box's and the 6 combo box's
Else
wsData.Cells(RecordRow, i).Value = .Value 'I believe this is part of AddRecord and populates worksheet with info from the 3 text box's and the 6 combo ' 'box's
End If
Else
If Action = xlGetRecord Then
.Value = CBool(LCase(wsData.Cells(RecordRow, i).Value) = "yes") ' I believe this Basically checks the box's if the incoming data from work sheet is Checked
Else
wsData.Cells(RecordRow, i).Value = IIf(.Value, "Yes", "No") 'I think this is to save a yes or no to worksheet depending on value of check box.
End If
End If
End With
Next i
End Sub
' these are the 15 form controls, first 3 text box's, next 6 combo boxes and then 6 check box's
Function FormControls() As Variant
FormControls = Array("Customer", "CSONumber", "JobNumber", _
"PCWeldType", "PCWeldGrind", "PCFinish", _
"NonPCWeld", "NonPCGrind", "NonPCFinish", _
"BRReview", "BOMReview", "DimReview", _
"WeldReview", "Apperance", "Complete")
End Function
Am I close?
thanks Bill