Hope everyone in the US had a great Thanksgiving. Here's the continuation of
my last question:
Albert this is what i have now, and it has a couple problems.
1. it actually asks me for the excel spreadsheet twice. why do we ask for
the name of the excel spreadsheet after doing the import?
2. I get an error at line CurrentDb.Execute strSQL
it says it expects 4 arguments?
3. on the front end of my database i'll need a piece of code that links to
a checkbox. if the user clicks the checkbox to true, the record is removed,
and replaced by the next valid record on the list, using the same rules we
used before to import the data in the first place. The point of this is that
if the user discovers that somoene mispelled "Mileage" (someone inevitably
will) that they can reject the record on that basis, and get another one. i
dont know how to do this front end to back end interaction.
4. Here's the code we have so far:
Public Function GetExcel(Optional strStartDir As String) As String
Dim strFilter As String
Dim lngFlags As Long
If strStartDir = "" Then
strStartDir = CurrentProject.Path
End If
strFilter = ahtAddFilterItem(strFilter, "Excel file (*.xls)", "*.xls")
GetExcel = ahtCommonFileOpenSave(InitialDir:=strStartDir, _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Select Excel sheet")
End Function
Sub MyExcelImport()
Dim strFile As String
Dim strSQL As String
CurrentDb.Execute "delete * from tableAppend"
strFile = GetExcel()
strFile = InputBox("Enter excel filename")
If strFile = "" Then
Exit Sub
End If
' import excel file...
DoCmd.TransferSpreadsheet acImport, , "tableAppend", strFile, True
strSQL = "INSERT INTO Random " & _
" ([postedamount], [reportname],[SAP Company Code])" & _
" select [postedamount], [reportname], [SAP Company Code]" & _
" from tableAppend " & _
" where ( (postedAmount >= 3500) or " & _
" ( (sapcompanycode in (010,528,185,113)) and (postedamount >= 1500) ) )"
CurrentDb.Execute strSQL
Dim rstAppend As DAO.Recordset
Dim rstRandom As DAO.Recordset
Dim lngRecordPtr As Long
strSQL = "select [postedamount], [reportname], [sapcompanycode]" & _
" from tableAppend " & _
" where (not ( (postedAmount >= 3500) or " & _
" ( (sapcompanycode in (010,528,185,113)) and (postedamount >= 1500) ) ))" _
& (Reportname <> "mile" Or "mileage" Or "mlg")
Set rstAppend = CurrentDb.OpenRecordset(strSQL)
Do While rstAppend.EOF = False
rstRandom.AddNew
rstRandom!PostedAmount = rstAppend!PostedAmount
rstRandom!ReprotName = rstAppend!Reportname
rstRandom!sapcompnaycode = rstAppend!sapcompnaycode
rstRandom.Update
rstAppend.Move 10
Loop
End Sub