Help understanding an expression or sub.

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.



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
 
Yeah I already changed that.... for the add row,
Tried the changes, and indeed the check box if saved checked when a search is done it is still checked
If updated unchecked then searched it shows unchecked.
But the Yes or no in column V does not change to match if record is updated.
If you add a record with the box checked, and shows it with a search, Column V says no
How or where it is storing the value for the check box is a mystery but it does not seem to be using column V
When a new part is added it always saves a no checked or not
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Yeah I already changed that.... for the add row,
Tried the changes, and indeed the check box if saved checked when a search is done it is still checked
If updated unchecked then searched it shows unchecked.
But the Yes or no in column V does not change to match if record is updated.
If you add a record with the box checked, and shows it with a search, Column V says no
How or where it is storing the value for the check box is a mystery but it does not seem to be using column V
When a new part is added it always saves a no checked or not


All those problems you mention seem to be problems of the original macro, the only thing I am changing is the column number.
You should first fix all those problems and then simply change the column number.

The macro you put works for me.
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,974
Members
448,934
Latest member
audette89

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