Can someone explain what this code is doing?

DK8

Registered User.
Local time
Today, 17:54
Joined
Apr 19, 2007
Messages
72
I have a code snippet here which I'm hoping someone can help me decipher:

Code:

strUpdate = "UPDATE [NO REASON LETTER REPORT TABLE] "

If (.Fields("DO NOT DISPLAY SSN").Value) Then
strSet = "SET [SORT FIELD1] = '" & RemoveSingleQuotes(strSort1) & "', " & _
"[SORT FIELD2] = '" & RemoveSingleQuotes(strSort2) & "', " & _
"[EMPLOYEE SSN] = ' ' "
Else
strSet = "SET [SORT FIELD1] = '" & RemoveSingleQuotes(strSort1) & "', " & _
"[SORT FIELD2] = '" & RemoveSingleQuotes(strSort2) & "' "
End If

Thank you in advance if you can provide me with any help!
 
Thank you, but I guess I should have more specific. I'm especially wondering what this line of code does:

"[EMPLOYEE SSN] = ' ' "

I need to ensure that SSN's aren't displayed on the report which generates from the data in no reason letter report table. I'm not sure that this line of code is serving that purpose or how to accomplish this. Thanks again if you can help me out!
 
Code:
  [color=green]'Save the beginning of the Update SQL in a variable[/color]
    strUpdate = "UPDATE [NO REASON LETTER REPORT TABLE] "
      
  [color=green]'If "Do Not Display SSN" field in "No Reason Letter Report Table" is true (checked)[/color]
    If (.Fields("DO NOT DISPLAY SSN").Value) Then
  [color=green]  
      'Set "Sort Field1" equal to strSort1 without single quotes
      'Set "Sort Field2" equal to strSort2 without single quotes
      'Put a blank value in "Employee SSN" field[/color]
        strSet = "SET [SORT FIELD1] = '" & RemoveSingleQuotes(strSort1) & "', " & _
                 "[SORT FIELD2] = '" & RemoveSingleQuotes(strSort2) & "', " & _
                 "[EMPLOYEE SSN] = ' ' "
    Else [color=green]
      'Set "Sort Field1" equal to strSort1 without single quotes
      'Set "Sort Field2" equal to strSort2 without single quotes[/color]
        strSet = "SET [SORT FIELD1] = '" & RemoveSingleQuotes(strSort1) & "', " & _
                 "[SORT FIELD2] = '" & RemoveSingleQuotes(strSort2) & "' "
    End If


But a better way to do this is to get rid of the duplicated code:

Code:
[color=green]  'Set "Sort Field1" equal to strSort1 without single quotes
  'Set "Sort Field2" equal to strSort2 without single quotes[/color]
    strUpdate = "UPDATE [NO REASON LETTER REPORT TABLE] " & _
                "SET [SORT FIELD1] = '" & RemoveSingleQuotes(strSort1) & "', " & _
                 "[SORT FIELD2] = '" & RemoveSingleQuotes(strSort2) & "'"

[color=green]  'If "Do Not Display SSN" field in "No Reason Letter Report Table" is true (checked)[/color]
    If (.Fields("DO NOT DISPLAY SSN").Value) Then
      [color=green]'Put a blank string in "Employee SSN" field[/color]
        strUpdate = strUpdate & ", [EMPLOYEE SSN] = '' "
    End If
 
Thanks for the suggestion, have a great weekend!
 

Users who are viewing this thread

Back
Top Bottom