VBA kode fejler pludselig
Jeg har et lille VBA skript som pludselig fejler (muligvis efter skifte til O065).Det går i sin enkelthed ud på at eksporterer nogle data til en CSV fil, som herefter kan importeres i Outlook. Det underlige er at der kun fejles på et felt - Email. Hvis jeg udelade feltet eller sætter et andet ind så virker det. Email feltet er defineret som short text 50 char.VBA er:
Dim strSQL As String
Dim rst As Recordset
Dim strLines As String
Dim fsoFile As Object
Dim strPath As String
Dim fld As DAO.Field
Dim L As Integer
Set fsoFile = CreateObject("Scripting.FileSystemObject")
Dim objFile As Object
strSQL = "SELECT * from Export_Mobil_Adresse_Detaljeret"
Set rst = CurrentDb.OpenRecordset(strSQL)
L = 0
strLines = ""
For Each fld In rst.Fields
If fld.Name <> "" Then
If L = 0 Then
strLines = fld.Name
L = L + 1
Else
strLines = strLines & "," & fld.Name
End If
End If
Next
strLines = strLines & vbCrLf
Do While Not rst.EOF
strLines = strLines & rst.Fields("Department") & ","
strLines = strLines & rst.Fields("Company") & ","
strLines = strLines & rst.Fields("Business Street") & ","
strLines = strLines & rst.Fields("Business Street2") & ","
strLines = strLines & rst.Fields("Business Postal Code") & ","
strLines = strLines & rst.Fields("Business City") & ","
strLines = strLines & rst.Fields("Company Main Phone") & ","
strLines = strLines & rst.Fields("Name") & ","
strLines = strLines & rst.Fields("Job Title") & ","
strLines = strLines & rst.Fields("E-mail") & ","
strLines = strLines & rst.Fields("Company") & ","
strLines = strLines & rst.Fields("Mobile Phone") & ","
strLines = strLines & rst.Fields("Business Phone") & vbCrLf
rst.MoveNext
Loop
strPath = CurrentProject.path & "\Export_Mobil_Adresse_Detaljeret.csv"
Set objFile = fsoFile.CreateTextFile(strPath)
objFile.WriteLine strLines
objFile.Close
Set fsoFile = Nothing
Set objFile = Nothing
Set rst = Nothing
MsgBox " Alle data er nu eksporteret"
*****
Jeg får en Run-time error 5, Invalid procedure call or argument.
på linien: objFile.WriteLine strLines