My code to transfer spreadsheets is picking up a invalid range somewhere. If I only import the ME file, I get all 52 fields, if I import both, in any order, I only get the first 32 fields of both files, as the EXP file only has 32 fields.
The excel files are being deownloaded from peoplesoft everyday with no changes to fields. I can't find any invalid data, which I don't think would be the issues since it will load correctly if I reset the flag on that file and rerun the code.
'**************************************START CODE**************************************
Public Function LoadPeopleSoftData()
'declare variable
Dim rs As ADODB.Recordset
'set variable equal to empty recordset
Set rs = New ADODB.Recordset
' set up variable to put the query statement into
Dim strSQL As String
' set variable equal to the query
strSQL = "SELECT * FROM tbl_PS_Files;"
' set variable to use for Match Exceptions
Dim stMEFile As String
' set variable to use for Expedites
Dim stExpFile As String
' set variable to Match Exception file name
stMEFile = "PH_ME_ALL_EXCEPTION_DETAILS_CR*"
' set variable to Expedite file name
stExpFile = "PH_EXPEDITE_PO_LINES*"
Dim iCounter, intNoOfRecs As Long
Dim varreturn As Long
'execute the query and load the results into the variable for the recordset
rs.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
intNoOfRecs = rs.RecordCount
varreturn = SysCmd(acSysCmdInitMeter, "Loading new files into system ", intNoOfRecs)
' loop through the records until there are no more
Do While Not rs.EOF
'Run code
Debug.Print rs("filename")
Debug.Print rs("loaded")
iCounter = iCounter + 1
'Update the Progress Meter to (intCounter/intNoOfRecs)%
varreturn = SysCmd(acSysCmdUpdateMeter, iCounter)
If rs("filename") Like stMEFile And rs("loaded") = "0" Then
' Load the Match Exceptions file
Call LoadME(rs("filename"))
' set flag on Match exception file to loaded
rs("Loaded") = 1
End If
If rs("filename") Like stExpFile And rs("Loaded") = "0" Then
' Load the Expedite file
Call LoadEXP(rs("Filename"))
' set flag on Expedite file to loaded
rs("loaded") = 1
End If
'move to the next item in the recordset before looping the code
rs.MoveNext
Loop
'Remove the Progress Meter
varreturn = SysCmd(acSysCmdClearStatus)
' close the recordset
rs.Close
' set the rs variable equal to nothing to free memory
Set rs = Nothing
End Function
'**************************************END CODE**************************************
'**************************************START CODE**************************************
Private Sub LoadME(strfilename As String)
'set query names to variables
Dim strq1 As String
Dim strq2 As String
Dim strq3 As String
Dim strq4 As String
Dim strfilepath As String
Dim strtable As String
Dim strSQL As String
' location of files to be loaded
strfilepath = "T:\MasterDatabase\QRY_MASTER_PeopleSoft\POManagementReports\"
' query used to remove yesterdays records from working file
strq1 = "qry_Delete_Yesterdays_MatchExceptions"
' query used to move imported records to working file
strq2 = "qry_Add_Todays_MatchException_Data"
' query used to find new buyers and add to the buyers table list
strq3 = "qry_New_MatchException_Buyer"
' will be used to capture totals for history and reporting
'strq4 = TBD qry
' table used to import the records to before moving to working file
strtable = "tbl_Match_Exception_RawLoad"
' SQL code to clear out the records from yesterday if they still exist
strSQL = "Delete * from tbl_Match_Exception_RawLoad"
' clear out the loading table
CurrentDb.Execute strSQL
'load new file into raw table
DoCmd.TransferSpreadsheet acImport, 8, strtable, strfilepath & strfilename, False, ""
' remove yesterday's working file records
DoCmd.OpenQuery strq1
' move records from raw table to working table
DoCmd.OpenQuery strq2
' check for new buyers and insert new ones into buyers table
DoCmd.OpenQuery strq3
' capurture totals for history
'DoCmd.OpenQuery strq4
' SQL code to clear out the records from that were just loaded into the working table
strSQL = "Delete * from tbl_Match_Exception_RawLoad"
End Sub
'**************************************START CODE**************************************
Private Sub LoadEXP(strfilename As String)
'set query names to variables
Dim strq1 As String
Dim strq2 As String
Dim strq3 As String
Dim strq4 As String
Dim strfilepath As String
Dim strtable As String
Dim strSQL As String
' query used to remove yesterdays records from working file
strq1 = "qry_Delete_Yesterdays_Expedites"
' query used to move imported records to working file
strq2 = "qry_Add_Todays_Expedites"
' query used to find new buyers and add to the buyers table list
strq3 = "qry_New_Expedites_Buyer"
' will be used to capture totals for history and reporting
'strq4 = tbd
strfilepath = "T:\MasterDatabase\QRY_MASTER_PeopleSoft\POManagementReports\"
' table used to import the records to before moving to working file
strtable = "tbl_Expedites_RawLoad"
' SQL code to clear out the records from yesterday if they still exist
strSQL = "Delete * from tbl_Expedites_RawLoad"
' clear out the loading table ensure fresh data
CurrentDb.Execute strSQL
'load new file into raw table
DoCmd.TransferSpreadsheet acImport, 8, strtable, strfilepath & strfilename, False, ""
' remove yesterday's expedites from working table
DoCmd.OpenQuery strq1
' move today's expedites from raw table to working table
DoCmd.OpenQuery strq2
' check for new buyers and add them to the buyers table
DoCmd.OpenQuery strq3
' clear out the loading table clear memory
CurrentDb.Execute strSQL
'**************************************END CODE**************************************
End Sub
The excel files are being deownloaded from peoplesoft everyday with no changes to fields. I can't find any invalid data, which I don't think would be the issues since it will load correctly if I reset the flag on that file and rerun the code.
'**************************************START CODE**************************************
Public Function LoadPeopleSoftData()
'declare variable
Dim rs As ADODB.Recordset
'set variable equal to empty recordset
Set rs = New ADODB.Recordset
' set up variable to put the query statement into
Dim strSQL As String
' set variable equal to the query
strSQL = "SELECT * FROM tbl_PS_Files;"
' set variable to use for Match Exceptions
Dim stMEFile As String
' set variable to use for Expedites
Dim stExpFile As String
' set variable to Match Exception file name
stMEFile = "PH_ME_ALL_EXCEPTION_DETAILS_CR*"
' set variable to Expedite file name
stExpFile = "PH_EXPEDITE_PO_LINES*"
Dim iCounter, intNoOfRecs As Long
Dim varreturn As Long
'execute the query and load the results into the variable for the recordset
rs.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
intNoOfRecs = rs.RecordCount
varreturn = SysCmd(acSysCmdInitMeter, "Loading new files into system ", intNoOfRecs)
' loop through the records until there are no more
Do While Not rs.EOF
'Run code
Debug.Print rs("filename")
Debug.Print rs("loaded")
iCounter = iCounter + 1
'Update the Progress Meter to (intCounter/intNoOfRecs)%
varreturn = SysCmd(acSysCmdUpdateMeter, iCounter)
If rs("filename") Like stMEFile And rs("loaded") = "0" Then
' Load the Match Exceptions file
Call LoadME(rs("filename"))
' set flag on Match exception file to loaded
rs("Loaded") = 1
End If
If rs("filename") Like stExpFile And rs("Loaded") = "0" Then
' Load the Expedite file
Call LoadEXP(rs("Filename"))
' set flag on Expedite file to loaded
rs("loaded") = 1
End If
'move to the next item in the recordset before looping the code
rs.MoveNext
Loop
'Remove the Progress Meter
varreturn = SysCmd(acSysCmdClearStatus)
' close the recordset
rs.Close
' set the rs variable equal to nothing to free memory
Set rs = Nothing
End Function
'**************************************END CODE**************************************
'**************************************START CODE**************************************
Private Sub LoadME(strfilename As String)
'set query names to variables
Dim strq1 As String
Dim strq2 As String
Dim strq3 As String
Dim strq4 As String
Dim strfilepath As String
Dim strtable As String
Dim strSQL As String
' location of files to be loaded
strfilepath = "T:\MasterDatabase\QRY_MASTER_PeopleSoft\POManagementReports\"
' query used to remove yesterdays records from working file
strq1 = "qry_Delete_Yesterdays_MatchExceptions"
' query used to move imported records to working file
strq2 = "qry_Add_Todays_MatchException_Data"
' query used to find new buyers and add to the buyers table list
strq3 = "qry_New_MatchException_Buyer"
' will be used to capture totals for history and reporting
'strq4 = TBD qry
' table used to import the records to before moving to working file
strtable = "tbl_Match_Exception_RawLoad"
' SQL code to clear out the records from yesterday if they still exist
strSQL = "Delete * from tbl_Match_Exception_RawLoad"
' clear out the loading table
CurrentDb.Execute strSQL
'load new file into raw table
DoCmd.TransferSpreadsheet acImport, 8, strtable, strfilepath & strfilename, False, ""
' remove yesterday's working file records
DoCmd.OpenQuery strq1
' move records from raw table to working table
DoCmd.OpenQuery strq2
' check for new buyers and insert new ones into buyers table
DoCmd.OpenQuery strq3
' capurture totals for history
'DoCmd.OpenQuery strq4
' SQL code to clear out the records from that were just loaded into the working table
strSQL = "Delete * from tbl_Match_Exception_RawLoad"
End Sub
'**************************************START CODE**************************************
Private Sub LoadEXP(strfilename As String)
'set query names to variables
Dim strq1 As String
Dim strq2 As String
Dim strq3 As String
Dim strq4 As String
Dim strfilepath As String
Dim strtable As String
Dim strSQL As String
' query used to remove yesterdays records from working file
strq1 = "qry_Delete_Yesterdays_Expedites"
' query used to move imported records to working file
strq2 = "qry_Add_Todays_Expedites"
' query used to find new buyers and add to the buyers table list
strq3 = "qry_New_Expedites_Buyer"
' will be used to capture totals for history and reporting
'strq4 = tbd
strfilepath = "T:\MasterDatabase\QRY_MASTER_PeopleSoft\POManagementReports\"
' table used to import the records to before moving to working file
strtable = "tbl_Expedites_RawLoad"
' SQL code to clear out the records from yesterday if they still exist
strSQL = "Delete * from tbl_Expedites_RawLoad"
' clear out the loading table ensure fresh data
CurrentDb.Execute strSQL
'load new file into raw table
DoCmd.TransferSpreadsheet acImport, 8, strtable, strfilepath & strfilename, False, ""
' remove yesterday's expedites from working table
DoCmd.OpenQuery strq1
' move today's expedites from raw table to working table
DoCmd.OpenQuery strq2
' check for new buyers and add them to the buyers table
DoCmd.OpenQuery strq3
' clear out the loading table clear memory
CurrentDb.Execute strSQL
'**************************************END CODE**************************************
End Sub