Hello hello,
I went to run a macro to produce a csv file like normal and I got a "Bad File name or number" error, and the file was only created with the headers.
the macro is as follows:
When I change the "Print #FileNumber..." line that is within the conditional to just:
Print #FileNumber,Field$("LASTNAME")
.. I don't get the error, but the file is just headers followed by a single last name.
The fields "Probation", "ProbtnHrsRemain", "DaysServiceRemain", "IncreaseCheck", and "Benefits" are all macro-derived.
Here is an example ("Probation"):
Any ideas would be much appreciated! Thank you!
I went to run a macro to produce a csv file like normal and I got a "Bad File name or number" error, and the file was only created with the headers.
the macro is as follows:
Code:
Option Explicit
Sub ProbToCSV()
Dim today as string
today = format$(Date$, "medium date")
Dim Filename as string
Filename = "C:\HRDocuments\Probation-(" + today + ").csv"
'Filename = "C:\Documents\HEU\Probation\Probation-(" + today + ").csv"
Dim FileNumber as Double
FileNumber = FreeFile
Open FileName For Output ACCESS Write Lock Read Write as FileNumber
Print #FileNumber,"Last Name,FirstName,Type,Position,Probation Status,Hours Worked,Hours Remaining,Days Remaining,PayRateCheck,Pay Rate,BenefitCheck,MSP,GroupHealth"
GetRandom 1
Dim i as integer
Dim FileNum as string
For i=1 to TotalRecords
If FileNum <> Field$("FILE#") Then
Print #FileNumber,Field$("LASTNAME")+","+Field$("FIRSTNAME")+","+Field$("EMPLOYEETYPE")+","+Field$("Pos")+","+Field$("Probation")+","+SumField$("Totalwkdhrs","Derived Field",1,"Sum")+","+Field$("ProbtnHrsRemain")+","+Field$("DaysServiceRemain")+","+Field$("IncreaseCheck")+","+Field$("RATE1AMT")+","+Field$("Benefits")+","+Field$("MSP")+","+Field$("GroupHealth")
FileNum = Field$("FILE#")
End If
GetNext
Next i
End Sub
When I change the "Print #FileNumber..." line that is within the conditional to just:
Print #FileNumber,Field$("LASTNAME")
.. I don't get the error, but the file is just headers followed by a single last name.
The fields "Probation", "ProbtnHrsRemain", "DaysServiceRemain", "IncreaseCheck", and "Benefits" are all macro-derived.
Here is an example ("Probation"):
Code:
Option Explicit
Sub Probation()
Dim EEType as string
EEType = Field$("EMPLOYEETYPE")
Dim Today as variant
Today = DateValue(Date$)
Dim HireDt
HireDt = DateValue(Field$("HIREDATEROE"))
Dim DaysService
DaysService = today - HireDt
Dim hours
hours = Val(SumField$("Totalwkdhrs","Derived Field",1,"Sum"))
If hours > 480 or DaysService > 180 Then
DerivedField "Past Probation"
Else
If EEType <> "C" Then
If DaysService > 90 Then
DerivedField "Past if working in Line for 3 months"
ElseIf hours >400 Then
DerivedField "Approaching Probation End"
Else
DerivedField "Probationary"
End If
ElseIf EEType = "C" Then
If DaysService > 160 or hours > 440 Then
DerivedField "Approaching Probation End"
Else
DerivedField "Probationary"
End If
End If
End If
End Sub
Any ideas would be much appreciated! Thank you!