T
ToddRhodesECI
Hey guys. I have the following script:
Private Sub btnExportFile_Click()
'On Error GoTo Err_btnExportFile_Click
Dim Script1 As String
Dim strSQL1 As String
Dim strSQL1Output As String
Dim strSQL2 As String
Dim strSQL2Output As String
Dim strSQL3 As String
Dim strSQL3Output As String
Dim strSQL4 As String
Dim strSQL4Output As String
Dim strSQL5 As String
Dim strSQL5Output As String
Dim strSQL6 As String
Dim strSQL6Output As String
Dim strSQL7 As String
Dim strSQL7Output As String
Dim strSQL8 As String
Dim strSQL8Output As String
Dim strSQL9 As String
Dim strSQL9Output As String
Dim intFile As Integer
Dim SQLOutput As String
Dim db As Database, rs As ADODB.Recordset
Set rs = New ADODB.Recordset
strSQL1 = "Select * from Part1"
rs.Open strSQL1, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
With rs
While Not .EOF
strSQL1Output = rs!Part1
.MoveNext
Wend
.Close
End With
Set rs = Nothing
MsgBox ("Section 1 Complete...")
Set rs = New ADODB.Recordset
strSQL2 = "Select * from Part2"
rs.Open strSQL2, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
With rs
While Not .EOF
strSQL2Output = rs!Part2
.MoveNext
Wend
.Close
End With
Set rs = Nothing
MsgBox ("Section 2 Complete...")
Set rs = New ADODB.Recordset
strSQL3 = "Select * from Part3"
rs.Open strSQL3, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
With rs
While Not .EOF
strSQL3Output = rs!Part3
.MoveNext
Wend
.Close
End With
Set rs = Nothing
MsgBox ("Section 3 Complete...")
Set rs = New ADODB.Recordset
strSQL4 = "Select * from Part4"
rs.Open strSQL4, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
With rs
While Not .EOF
strSQL4Output = rs!Part4
.MoveNext
Wend
.Close
End With
Set rs = Nothing
MsgBox ("Section 4 Complete...")
If txtDivision = "" Then
txtDivision = Null
End If
Script1 = "insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('ADIServerName','" & txtCompanyCode & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue) Values('ADIDBName'
,'ADI_" & txtCompanyCode & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Pay_Group_ID','" & txtPayGroupID & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue) Values('Shift_ID','"
& txtShiftID & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Accrual_Group_ID','" & txtAccrualGroupID & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Points_Group_ID','" & txtPointsGroupID & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue) Values('Super_ID','"
& txtSuperID & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Auto_Punch','" & txtAutoPunch & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Allow_Web_Entry','" & txtAllowWebEntry & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Paid_Holidays','" & txtPaidHolidays & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue) Values('Loc_ID','" &
txtLocID & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue) Values('Div_Code','"
& txtDivCode & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue) Values('Get_Rate','"
& txtGetRate & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Card_Override','" & txtCardOverride & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('DownloadRateToADI','" & txtDownloadRateToADI & "')" & vbCrLf &
_
"insert dbo.ADI_Departments (Loc_ID,Div_Code,Dept_Code,Position)
Values('" & txtLocation & "','" & txtDivision & "','" & txtDepartment &
"','" & txtPosition & "')" & vbCrLf & _
"insert dbo.ADI_Filter (EmpowerTable,EmpowerField,FilterValue)
Values('" & txtEmpowerTable & "','" & txtEmpowerField & "','" &
txtFilterValue & "')"
intFile = FreeFile
'Open "C:\" & txtCompanyCode & " - Integration Script.txt" For
Output As intFile
Open "\\eci-dzoflw13xtv\adi\test.txt" For Output As intFile
Print #intFile, strSQL1Output & vbCrLf & vbCrLf & Script1 & vbCrLf
& _
vbCrLf & strSQL2Output & vbCrLf & vbCrLf & strSQL3Output & vbCrLf &
vbCrLf & strSQL4Output
MsgBox (txtCompanyCode & " - Integration Script.txt Created!")
Close intFile
Exit_btnExportFile_Click:
Exit Sub
'Err_btnExportFile_Click:
' MsgBox Err.Description
' Resume Exit_btnExportFile_Click
End Sub
Private Sub btnCloseForm_Click()
On Error GoTo Err_btnCloseForm_Click
DoCmd.Close
Exit_btnCloseForm_Click:
Exit Sub
Err_btnCloseForm_Click:
MsgBox Err.Description
Resume Exit_btnCloseForm_Click
End Sub
If I try to run this on my work laptop (winXP SP2, Office 2003, just
updated today with all the latest updates for troubleshooting
purposes), I get an error: 54, Bad File Mode every time I try to run
it. I have tried writing to C:/, a new share on my machine with "Full
Control" access for Everyone, nothing seems to fix it.
If I run the same script at home (same specs, winXP2, Office 2003 just
recently updated), it works without a problem.
So, the syntax should be correct. I had my LAN administrator disable my
Kaspersky Anti-Virus for troubleshooting, but that didn't fix it. I can
run my laptop as local administrator and it still doesn't work. I
really need this to work but can't get it for the life of me. That it
works at home is great for letting me know that I wrote it correctly,
but it doesn't help me get my work done. If anyone can help out at all,
I'm willing to try anything. Thank you much for your time!
Todd Rhodes
Implementation Analyst, ECI Inc.
Private Sub btnExportFile_Click()
'On Error GoTo Err_btnExportFile_Click
Dim Script1 As String
Dim strSQL1 As String
Dim strSQL1Output As String
Dim strSQL2 As String
Dim strSQL2Output As String
Dim strSQL3 As String
Dim strSQL3Output As String
Dim strSQL4 As String
Dim strSQL4Output As String
Dim strSQL5 As String
Dim strSQL5Output As String
Dim strSQL6 As String
Dim strSQL6Output As String
Dim strSQL7 As String
Dim strSQL7Output As String
Dim strSQL8 As String
Dim strSQL8Output As String
Dim strSQL9 As String
Dim strSQL9Output As String
Dim intFile As Integer
Dim SQLOutput As String
Dim db As Database, rs As ADODB.Recordset
Set rs = New ADODB.Recordset
strSQL1 = "Select * from Part1"
rs.Open strSQL1, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
With rs
While Not .EOF
strSQL1Output = rs!Part1
.MoveNext
Wend
.Close
End With
Set rs = Nothing
MsgBox ("Section 1 Complete...")
Set rs = New ADODB.Recordset
strSQL2 = "Select * from Part2"
rs.Open strSQL2, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
With rs
While Not .EOF
strSQL2Output = rs!Part2
.MoveNext
Wend
.Close
End With
Set rs = Nothing
MsgBox ("Section 2 Complete...")
Set rs = New ADODB.Recordset
strSQL3 = "Select * from Part3"
rs.Open strSQL3, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
With rs
While Not .EOF
strSQL3Output = rs!Part3
.MoveNext
Wend
.Close
End With
Set rs = Nothing
MsgBox ("Section 3 Complete...")
Set rs = New ADODB.Recordset
strSQL4 = "Select * from Part4"
rs.Open strSQL4, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
With rs
While Not .EOF
strSQL4Output = rs!Part4
.MoveNext
Wend
.Close
End With
Set rs = Nothing
MsgBox ("Section 4 Complete...")
If txtDivision = "" Then
txtDivision = Null
End If
Script1 = "insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('ADIServerName','" & txtCompanyCode & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue) Values('ADIDBName'
,'ADI_" & txtCompanyCode & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Pay_Group_ID','" & txtPayGroupID & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue) Values('Shift_ID','"
& txtShiftID & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Accrual_Group_ID','" & txtAccrualGroupID & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Points_Group_ID','" & txtPointsGroupID & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue) Values('Super_ID','"
& txtSuperID & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Auto_Punch','" & txtAutoPunch & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Allow_Web_Entry','" & txtAllowWebEntry & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Paid_Holidays','" & txtPaidHolidays & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue) Values('Loc_ID','" &
txtLocID & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue) Values('Div_Code','"
& txtDivCode & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue) Values('Get_Rate','"
& txtGetRate & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('Card_Override','" & txtCardOverride & "')" & vbCrLf & _
"insert dbo.ADI_Defaults (ADI_Field,DefaultValue)
Values('DownloadRateToADI','" & txtDownloadRateToADI & "')" & vbCrLf &
_
"insert dbo.ADI_Departments (Loc_ID,Div_Code,Dept_Code,Position)
Values('" & txtLocation & "','" & txtDivision & "','" & txtDepartment &
"','" & txtPosition & "')" & vbCrLf & _
"insert dbo.ADI_Filter (EmpowerTable,EmpowerField,FilterValue)
Values('" & txtEmpowerTable & "','" & txtEmpowerField & "','" &
txtFilterValue & "')"
intFile = FreeFile
'Open "C:\" & txtCompanyCode & " - Integration Script.txt" For
Output As intFile
Open "\\eci-dzoflw13xtv\adi\test.txt" For Output As intFile
Print #intFile, strSQL1Output & vbCrLf & vbCrLf & Script1 & vbCrLf
& _
vbCrLf & strSQL2Output & vbCrLf & vbCrLf & strSQL3Output & vbCrLf &
vbCrLf & strSQL4Output
MsgBox (txtCompanyCode & " - Integration Script.txt Created!")
Close intFile
Exit_btnExportFile_Click:
Exit Sub
'Err_btnExportFile_Click:
' MsgBox Err.Description
' Resume Exit_btnExportFile_Click
End Sub
Private Sub btnCloseForm_Click()
On Error GoTo Err_btnCloseForm_Click
DoCmd.Close
Exit_btnCloseForm_Click:
Exit Sub
Err_btnCloseForm_Click:
MsgBox Err.Description
Resume Exit_btnCloseForm_Click
End Sub
If I try to run this on my work laptop (winXP SP2, Office 2003, just
updated today with all the latest updates for troubleshooting
purposes), I get an error: 54, Bad File Mode every time I try to run
it. I have tried writing to C:/, a new share on my machine with "Full
Control" access for Everyone, nothing seems to fix it.
If I run the same script at home (same specs, winXP2, Office 2003 just
recently updated), it works without a problem.
So, the syntax should be correct. I had my LAN administrator disable my
Kaspersky Anti-Virus for troubleshooting, but that didn't fix it. I can
run my laptop as local administrator and it still doesn't work. I
really need this to work but can't get it for the life of me. That it
works at home is great for letting me know that I wrote it correctly,
but it doesn't help me get my work done. If anyone can help out at all,
I'm willing to try anything. Thank you much for your time!
Todd Rhodes
Implementation Analyst, ECI Inc.