I have an spreadsheet that contains emplyee data most employees have several rows I need to place the multiple rows into just one row, With you guys help I was able to get it to work somewhat. Now I'm getting and error on the following line here is the code:
Here is where stop running: If EmpNum <> RS!a Or I >= 30 Then
I just can't figure out why.
Thanks for your help
Rafael
Public Function Transfer_To_Non_Normalized
_CSV()
Dim DB As Database
Dim RS As Recordset
Dim I As Integer
Dim EmpNum As String
Dim FileNum As Integer
Dim FileNameAndPath As String
Dim WriteIt As Boolean
Dim OutputLine As String
FileNum = FreeFile()
FileNameAndPath = "centene.csv" 'Path and file name to export to
Set DB = CurrentDb() 'Use the current database
Set RS = DB.OpenRecordset("centene"
) 'actually open the recordset
If RS.EOF = False Then
RS.MoveFirst
Else
MsgBox "No Data", vbExclamation, "Exiting Fuction"
Set RS = Nothing
Set DB = Nothing
Exit Function
End If
'Open the file for output
Open FileNameAndPath For Output Access Write Lock Write As FileNum
I = 0
OutputLine = ""
WriteIt = False
EmpNum = RS!a
'start outputting the data
Do Until RS.EOF
If WriteIt = True Then
Print #FileNum, OutputLine
Debug.Print OutputLine
WriteIt = False
OutputLine = ""
I = 0
End If
Do Until I >= 30
If OutputLine <> "" Then
OutputLine = OutputLine & "," & RS!a & "," & RS!b & "," & RS!c & "," & RS!d & _
"," & RS!e & "," & RS!f & "," & RS!g & "," & RS!h & _
"," & RS!j & "," & RS!k & "," & RS!l
Else
OutputLine = RS!a & "," & RS!b & "," & RS!c & "," & RS!d & "," & _
RS!e & "," & RS!f & "," & RS!g & "," & RS!h & "," & _
RS!j & "," & RS!k & "," & RS!l
End If
RS.MoveNext
If EmpNum <> RS!a Or I >= 30 Then
WriteIt = True
EmpNum = RS!a
Exit Do
End If
I = I + 1
Loop
Loop
Print #FileNum, OutputLine
Debug.Print OutputLine
Close #FileNum
Set RS = Nothing
Set DB = Nothing
End Function
Start Free Trial