G
Guest
Howdy, all1
I'm pretty darn good with Access and VB, but have a problem that's got me
stumped. It seems not all "msaccess.exe" pigs are not created equal.
Got an application that spits out summary table data to an external
database. The catch is that the new (external) database must in Access 2000
format (Feds, go figure.) To help automate what otherwise was a
time-consuming mess to convert, I added the
'application.convertaccessproject' method in my code. Problem is this: It
works pefect on my machine, but pops an error message on other machines that
"blah blah MS Acccess couldn't convert the database..." Stupid program does
the conversion nonetheless, but stops the code (goes into error mode) and
doesn't give the final dialog box.
I used the recommended code right from MS, and like I say, it works perfect
on my PC. All the references and libs are identical on both machines.
(Standard Office install.)
Ideas? Thanks to anybody who might have an insight to this oddity. BTW:
The code here may appear "Rube Goldberg" but that it has worked for years
without trouble, and to meet government reporting rules. Long story.
Thanks.
---------------------------------------------
Private Sub btnCreatePDR_Click()
Dim db As Database
Dim rs As Recordset
Dim sDate As String
Dim filename As String
Dim altfilename As String
Dim PDRFileName As String
Dim reportname As String
Dim altreportname As String
Dim Month As String
Dim Year As String
Dim PDRDir As String
Set db = CurrentDb
Set rs = db.OpenRecordset("INIADM")
'Set PDRDir = rs!PDRDir
Month = cboMonth
Year = Right(cboYear, 2)
'Next assign a provisional file name as DHLAmmyyA3 or S3 to denote a
2002-2003 file format. further code will convert it to a 2000 format
'Save the 2002-2003 file; Assign alternate file names for the 2000 format
file name
If Me.Program = "AQP" Then
reportname = "DHLA" & Month & Year & "a3" 'for 2002-2003 format (Temp
use for code only)
altreportname = "DHLA" & Month & Year & "a" 'for 2000 format (Permanent
copy for AFS-230)
ElseIf Me.Program = "SVT" Then 'for SVT data file only
reportname = "DHLA" & Month & Year & "s3" 'for 2002-2003 format (Temp
use for code only)
altreportname = "DHLA" & Month & Year & "s" 'for 2000 format (Permanent
copy for AFS-230)
End If
filename = rs!PDRDir & "\" & reportname & ".mdb"
altfilename = rs!PDRDir & "\" & altreportname & ".mdb"
If Dir(filename, 0) <> "" Then Kill filename
If Dir(altfilename, 0) <> "" Then Kill altfilename
CreateDatabase filename, dbLangGeneral 'create shell database DHLAmmyyA3 or S3
If Me.Program = "AQP" Then 'all three AQP tables
DoCmd.CopyObject filename, "Claim", acTable, "Claim" 'added 17 Jul 06
per Eric; confidentiality claim
DoCmd.CopyObject filename, "PDRT", acTable, "FAASVTPDR"
DoCmd.CopyObject filename, "SKLRSN", acTable, "FAASVTSKLRSN"
DoCmd.CopyObject filename, "TORT", acTable, "FAATORT"
ElseIf Me.Program = "SVT" Then 'SVT tables only
DoCmd.CopyObject filename, "Claim", acTable, "Claim" 'added 17 Jul 06
per Eric; confidentiality claim
DoCmd.CopyObject filename, "PDRT", acTable, "FAASVTPDR"
DoCmd.CopyObject filename, "SKLRSN", acTable, "FAASVTSKLRSN"
End If
Me.PDRFileName = altfilename 'Final name on the form (lower right box)
'2002-2003 file format has been created and saved. Now convert the file to
Access 2000 for AFS-230 'Added 12 Jun 2006
'Now take the provisional file name (2003 format) and convert it Access 2000
format
Application.ConvertAccessProject _
SourceFilename:=filename, _
DestinationFilename:=altfilename, _
destinationfileformat:=acFileFormatAccess2000
'If Dir(filename) <> "" Then Kill filename 'delete the 2002-2003 formatted
file, not needed.
If IsNull(rs!PDRDir) And Dir(altfilename) <> "" Then
Select Case MsgBox("The selected month was successfully created as PDR
file: " & altfilename & "." _
& Chr(10) & "" _
& Chr(10) & "The file was saved in the root directory because
you did not set a default directory." _
& Chr(10) & "Please set a default directory to stop seeing this
error message!" _
& Chr(10) & "" _
& Chr(10) & "Would you like to open the e-mail shell now and
send the file?", vbQuestion + vbOKCancel + vbDefaultButton2, "ASOK PDR
Builder")
Case vbOK
DoCmd.RunMacro ("PDR Email Shell")
Case vbCancel
End Select
ElseIf Not IsNull(rs!PDRDir) And Dir(altfilename) <> "" Then
Select Case MsgBox("The selected month was successfully created as PDR
file: " & altfilename & "." _
& Chr(10) & "This is the file to send to AFS-230. Good Job!" _
& Chr(10) & "" _
& Chr(10) & "Would you like to open the e-mail shell now and
send the file?", vbQuestion + vbOKCancel + vbDefaultButton2, "ASOK PDR Send")
Case vbOK
DoCmd.RunMacro ("PDR Email Shell")
Case vbCancel
End Select
End If
Exit_btnCreatePDR_Click:
Exit Sub
Err_btnCreatePDR_Click:
LogEvent Err, "frmDataCollection,btnCreatePDR_Click: " & Err.Description
' MsgBox Err.Description
Resume Exit_btnCreatePDR_Click
End Sub
I'm pretty darn good with Access and VB, but have a problem that's got me
stumped. It seems not all "msaccess.exe" pigs are not created equal.
Got an application that spits out summary table data to an external
database. The catch is that the new (external) database must in Access 2000
format (Feds, go figure.) To help automate what otherwise was a
time-consuming mess to convert, I added the
'application.convertaccessproject' method in my code. Problem is this: It
works pefect on my machine, but pops an error message on other machines that
"blah blah MS Acccess couldn't convert the database..." Stupid program does
the conversion nonetheless, but stops the code (goes into error mode) and
doesn't give the final dialog box.
I used the recommended code right from MS, and like I say, it works perfect
on my PC. All the references and libs are identical on both machines.
(Standard Office install.)
Ideas? Thanks to anybody who might have an insight to this oddity. BTW:
The code here may appear "Rube Goldberg" but that it has worked for years
without trouble, and to meet government reporting rules. Long story.
Thanks.
---------------------------------------------
Private Sub btnCreatePDR_Click()
Dim db As Database
Dim rs As Recordset
Dim sDate As String
Dim filename As String
Dim altfilename As String
Dim PDRFileName As String
Dim reportname As String
Dim altreportname As String
Dim Month As String
Dim Year As String
Dim PDRDir As String
Set db = CurrentDb
Set rs = db.OpenRecordset("INIADM")
'Set PDRDir = rs!PDRDir
Month = cboMonth
Year = Right(cboYear, 2)
'Next assign a provisional file name as DHLAmmyyA3 or S3 to denote a
2002-2003 file format. further code will convert it to a 2000 format
'Save the 2002-2003 file; Assign alternate file names for the 2000 format
file name
If Me.Program = "AQP" Then
reportname = "DHLA" & Month & Year & "a3" 'for 2002-2003 format (Temp
use for code only)
altreportname = "DHLA" & Month & Year & "a" 'for 2000 format (Permanent
copy for AFS-230)
ElseIf Me.Program = "SVT" Then 'for SVT data file only
reportname = "DHLA" & Month & Year & "s3" 'for 2002-2003 format (Temp
use for code only)
altreportname = "DHLA" & Month & Year & "s" 'for 2000 format (Permanent
copy for AFS-230)
End If
filename = rs!PDRDir & "\" & reportname & ".mdb"
altfilename = rs!PDRDir & "\" & altreportname & ".mdb"
If Dir(filename, 0) <> "" Then Kill filename
If Dir(altfilename, 0) <> "" Then Kill altfilename
CreateDatabase filename, dbLangGeneral 'create shell database DHLAmmyyA3 or S3
If Me.Program = "AQP" Then 'all three AQP tables
DoCmd.CopyObject filename, "Claim", acTable, "Claim" 'added 17 Jul 06
per Eric; confidentiality claim
DoCmd.CopyObject filename, "PDRT", acTable, "FAASVTPDR"
DoCmd.CopyObject filename, "SKLRSN", acTable, "FAASVTSKLRSN"
DoCmd.CopyObject filename, "TORT", acTable, "FAATORT"
ElseIf Me.Program = "SVT" Then 'SVT tables only
DoCmd.CopyObject filename, "Claim", acTable, "Claim" 'added 17 Jul 06
per Eric; confidentiality claim
DoCmd.CopyObject filename, "PDRT", acTable, "FAASVTPDR"
DoCmd.CopyObject filename, "SKLRSN", acTable, "FAASVTSKLRSN"
End If
Me.PDRFileName = altfilename 'Final name on the form (lower right box)
'2002-2003 file format has been created and saved. Now convert the file to
Access 2000 for AFS-230 'Added 12 Jun 2006
'Now take the provisional file name (2003 format) and convert it Access 2000
format
Application.ConvertAccessProject _
SourceFilename:=filename, _
DestinationFilename:=altfilename, _
destinationfileformat:=acFileFormatAccess2000
'If Dir(filename) <> "" Then Kill filename 'delete the 2002-2003 formatted
file, not needed.
If IsNull(rs!PDRDir) And Dir(altfilename) <> "" Then
Select Case MsgBox("The selected month was successfully created as PDR
file: " & altfilename & "." _
& Chr(10) & "" _
& Chr(10) & "The file was saved in the root directory because
you did not set a default directory." _
& Chr(10) & "Please set a default directory to stop seeing this
error message!" _
& Chr(10) & "" _
& Chr(10) & "Would you like to open the e-mail shell now and
send the file?", vbQuestion + vbOKCancel + vbDefaultButton2, "ASOK PDR
Builder")
Case vbOK
DoCmd.RunMacro ("PDR Email Shell")
Case vbCancel
End Select
ElseIf Not IsNull(rs!PDRDir) And Dir(altfilename) <> "" Then
Select Case MsgBox("The selected month was successfully created as PDR
file: " & altfilename & "." _
& Chr(10) & "This is the file to send to AFS-230. Good Job!" _
& Chr(10) & "" _
& Chr(10) & "Would you like to open the e-mail shell now and
send the file?", vbQuestion + vbOKCancel + vbDefaultButton2, "ASOK PDR Send")
Case vbOK
DoCmd.RunMacro ("PDR Email Shell")
Case vbCancel
End Select
End If
Exit_btnCreatePDR_Click:
Exit Sub
Err_btnCreatePDR_Click:
LogEvent Err, "frmDataCollection,btnCreatePDR_Click: " & Err.Description
' MsgBox Err.Description
Resume Exit_btnCreatePDR_Click
End Sub