I am exporting data to an .xls spreadsheet and currently the data is all getting lumped into the first cell A1. Is there an easy way to get the data to seperate into different cells? I want first name in A1, last name in B1, SSN in C1, employee paid premium in D1 and cancel date in E1. Then when the system encounters first name a second time, it should start a new row and so on. I have attached the code for your review, thanks in advance for any help that anyone can provide.
Function Build_UNUM_Provident_Payment_File(ByVal lngCarrier As Long)
On Error GoTo ERR_HANDLER
Dim rstRecs As ADODB.Recordset
Dim strFileName As String
Dim strSQL As String
Dim lngEmployerNo As Long
Dim varRetVal As Variant
Dim intRow As Integer
Dim intColumn As Integer
Dim intCounter As Integer
Dim blnOpenLocally As Boolean
blnOpenLocally = OpenGlobalOLEDBConnection()
Set rstRecs = CreateObject("ADODB.RECORDSET")
strSQL = "exec spSelectUNUMProvidentPaymentFile "
strSQL = strSQL & ReturnFieldArgument("@CarrierNumber", lngCarrier, True, False)
With rstRecs
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.ActiveConnection = g_conOLEDB
.Open strSQL
Set .ActiveConnection = Nothing
intRow = 1
intColumn = 1
intRow = intRow + 1
intColumn = intColumn + 1
intCounter = intCounter + 1
lngEmployerNo = 0
If (Not (.EOF)) Then
strFileName = CreateNightBatchDirectory() & "Payments\UNUMProvident" & lngCarrier & "Client" & .Fields("EMPLOYER NUMBER").Value & ".xls"
Open strFileName For Output As #1
Add_Email_Process_Record True, 1, lngCarrier, strFileName, False, CInt(Asc("P") & Asc("F"))
Add_Daily_Process_Record "UNUMProvident" & lngCarrier, strFileName
Do While (Not (.EOF))
lngEmployerNo = .Fields("EMPLOYER NUMBER").Value
If (Not (BlankField(.Fields("FIRST NAME").Value))) Then
Print #1, Format(Left(.Fields("FIRST NAME").Value, 15), "!@@@@@@@@@@@@@@@");
Else
Print #1, Space$(15);
End If
If (Not (BlankField(.Fields("LAST NAME").Value))) Then
Print #1, Format(Left(.Fields("LAST NAME").Value, 15), "!@@@@@@@@@@@@@@@");
Else
Print #1, Space$(15);
End If
Print #1, Format(Left((rstRecs![EMPLOYEE SSN]), 9), "@@-@@@-@@@@");
If (Not (BlankField(.Fields("EMPLOYEE PAID PREMIUM").Value))) Then
Print #1, Format(Left(.Fields("EMPLOYEE PAID PREMIUM").Value, 10), "0000000.00");
Else
Print #1, Space$(10);
End If
If (Not (BlankField(.Fields("CANCEL DATE").Value))) Then
Print #1, Format(Left(.Fields("CANCEL DATE").Value, 10), "MM/DD/YYYY")
Print #1, Space$(2);
Else
Print #1, Space$(12);
End If
Print #1,
Print #1,
.MoveNext
Loop
Close #1
End If
End With
rstRecs.Close
Set rstRecs = Nothing
Exit Function
If (blnOpenLocally) Then
CloseGlobalOLEDBConnection
End If
ERR_HANDLER:
Close #1
If (rstRecs.STATE = adStateOpen) Then
varRetVal = Generate_ADOError_Report(g_conOLEDB, Application.CurrentObjectName & " Build_UNUM_Provident_Payment_File ", _
Err.Number & Err.DESCRIPTION & " SSN- " & rstRecs.Fields("EMPLOYEE SSN").Value)
rstRecs.Close
Else
varRetVal = Generate_ADOError_Report(g_conOLEDB, Application.CurrentObjectName & " Build_UNUM_Provident_Payment_File ", _
Err.Number & Err.DESCRIPTION & " RECORDSET NOT OPEN")
End If
If (blnOpenLocally) Then
CloseGlobalOLEDBConnection
End If
Halt_Night_Batch
End Function
Function Build_UNUM_Provident_Payment_File(ByVal lngCarrier As Long)
On Error GoTo ERR_HANDLER
Dim rstRecs As ADODB.Recordset
Dim strFileName As String
Dim strSQL As String
Dim lngEmployerNo As Long
Dim varRetVal As Variant
Dim intRow As Integer
Dim intColumn As Integer
Dim intCounter As Integer
Dim blnOpenLocally As Boolean
blnOpenLocally = OpenGlobalOLEDBConnection()
Set rstRecs = CreateObject("ADODB.RECORDSET")
strSQL = "exec spSelectUNUMProvidentPaymentFile "
strSQL = strSQL & ReturnFieldArgument("@CarrierNumber", lngCarrier, True, False)
With rstRecs
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.ActiveConnection = g_conOLEDB
.Open strSQL
Set .ActiveConnection = Nothing
intRow = 1
intColumn = 1
intRow = intRow + 1
intColumn = intColumn + 1
intCounter = intCounter + 1
lngEmployerNo = 0
If (Not (.EOF)) Then
strFileName = CreateNightBatchDirectory() & "Payments\UNUMProvident" & lngCarrier & "Client" & .Fields("EMPLOYER NUMBER").Value & ".xls"
Open strFileName For Output As #1
Add_Email_Process_Record True, 1, lngCarrier, strFileName, False, CInt(Asc("P") & Asc("F"))
Add_Daily_Process_Record "UNUMProvident" & lngCarrier, strFileName
Do While (Not (.EOF))
lngEmployerNo = .Fields("EMPLOYER NUMBER").Value
If (Not (BlankField(.Fields("FIRST NAME").Value))) Then
Print #1, Format(Left(.Fields("FIRST NAME").Value, 15), "!@@@@@@@@@@@@@@@");
Else
Print #1, Space$(15);
End If
If (Not (BlankField(.Fields("LAST NAME").Value))) Then
Print #1, Format(Left(.Fields("LAST NAME").Value, 15), "!@@@@@@@@@@@@@@@");
Else
Print #1, Space$(15);
End If
Print #1, Format(Left((rstRecs![EMPLOYEE SSN]), 9), "@@-@@@-@@@@");
If (Not (BlankField(.Fields("EMPLOYEE PAID PREMIUM").Value))) Then
Print #1, Format(Left(.Fields("EMPLOYEE PAID PREMIUM").Value, 10), "0000000.00");
Else
Print #1, Space$(10);
End If
If (Not (BlankField(.Fields("CANCEL DATE").Value))) Then
Print #1, Format(Left(.Fields("CANCEL DATE").Value, 10), "MM/DD/YYYY")
Print #1, Space$(2);
Else
Print #1, Space$(12);
End If
Print #1,
Print #1,
.MoveNext
Loop
Close #1
End If
End With
rstRecs.Close
Set rstRecs = Nothing
Exit Function
If (blnOpenLocally) Then
CloseGlobalOLEDBConnection
End If
ERR_HANDLER:
Close #1
If (rstRecs.STATE = adStateOpen) Then
varRetVal = Generate_ADOError_Report(g_conOLEDB, Application.CurrentObjectName & " Build_UNUM_Provident_Payment_File ", _
Err.Number & Err.DESCRIPTION & " SSN- " & rstRecs.Fields("EMPLOYEE SSN").Value)
rstRecs.Close
Else
varRetVal = Generate_ADOError_Report(g_conOLEDB, Application.CurrentObjectName & " Build_UNUM_Provident_Payment_File ", _
Err.Number & Err.DESCRIPTION & " RECORDSET NOT OPEN")
End If
If (blnOpenLocally) Then
CloseGlobalOLEDBConnection
End If
Halt_Night_Batch
End Function