Advertisement
Advertisement
| 09.08.2008 at 09:10PM PDT, ID: 23714308 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: |
Public Function OpenExcelDocument(Path)
Set ExcelApp = Server.CreateObject("Excel.Application")
Set Workbook = ExcelApp.Workbooks.Open(Path)
Set WorkSheet = Workbook.WorkSheets(1)
End Function
Public Function CloseExcelDocument()
ExcelApp.Application.Quit
Set WorkSheet = Nothing
Set ExcelApp = Nothing
End Function
Public Function MoveFirst()
' ** move to the first product ** '
CurrentProductRow = ProductStartRow
MoveNext
End Function
Public Function MoveNext()
' ** move to next product ** '
Dim y
if(CurrentProductRow>-1) Then
y = CLng(CurrentProductRow+1)
For i = y To 300
If(Trim(WorkSheet.Range("A" & i).Value)<>"") Then
' ** product found! ** '
CurrentProductRow = i
Exit Function
End If
Next
End If
' ** no new product found! ** '
CurrentProductRow = -1
End Function
Public Function GetRow()
If(CurrentProductRow>-1) Then
Set GetRow = WorkSheet.Rows(CurrentProductRow)
Else
Set GetRow = Nothing
End If
End Function
Public Function DoPage()
OpenExcelDocument(Server.MapPath("data3.xls"))
MoveFirst
Dim row
Set row = GetRow()
Do While Not row Is Nothing
sPagina = Trim(row.cells(3).value)
' ** create your insert statement and fire it to the database.
MoveNext
Set row = GetRow()
Loop
Set row = Nothing
CloseExcelDocument
End Function
' ** call DoPage somewhere...
Excel to access
Public Function bImportExcelWorksheet(ByVal sExcelFilePath As String, _
ByVal sExcelFileName As String, _
ByVal sSheetName As String, _
ByVal iFirstDataRow As Integer, _
ByVal sTable As String) As Boolean
' Excel object variables
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet
' Access object variables
Dim dbs As DAO.Database
Dim rstRead As DAO.Recordset
Dim rstWrite As DAO.Recordset
Dim fld As DAO.Field
' Declared variables
Dim bytWks As Byte
Dim bytMaxPages As Byte
Dim intStartRow As Integer
Dim strData As String
Dim intMaxRow As Integer
Dim strSQL As String
Dim strMsg As String
Dim intLastCol As Integer
Dim intRow As Integer
Dim intRec As Integer
Dim strCurrFld As String
Dim intCol As Integer
Dim intLen As Integer
Dim varValue As Variant
Dim lngErrs As Long
Dim bReturn As Boolean
Dim sFile As String
On Error GoTo ProcessFileImport_Error
' Assume sucsess, If an error occurs the error handler will set the flag to false
bReturn = True
'DoCmd.Hourglass True
' Create the Excel Applicaiton, Workbook and Worksheet and Database object
sFile = sExcelFilePath & sExcelFileName
Set appExcel = Excel.Application
Set wbk = appExcel.Workbooks.Open(sFile)
Set dbs = CurrentDb
Set wks = wbk.Worksheets(sSheetName) ' Load current worksheet.
intStartRow = iFirstDataRow ' Set to the first row that contains actual data.
' Initialize variables
Set rstRead = Nothing
intRow = intStartRow
strData = ""
' Find used range to determine row count.
' Value is saved in intMaxRow
strData = wks.UsedRange.Address
intMaxRow = CInt(Mid(strData, InStrRev(strData, "$")))
strSQL = "SELECT [varAccessField], [bytOrdinalPosition] FROM tblCFI_PricingDataColumnSpecs " & _
"WHERE [varImportName]='" & sTable & "' ORDER BY [bytOrdinalPosition] ASC;"
Set rstRead = dbs.OpenRecordset(strSQL, dbOpenDynaset)
' If there is a mistake and no specification exists, then exit with message
If rstRead.BOF And rstRead.EOF Then
strMsg = "The import spec was not found. Cannot continue."
MsgBox strMsg, vbExclamation, "Error"
Else
rstRead.MoveLast
rstRead.MoveFirst
intLastCol = rstRead.RecordCount
' The name of the import and destination table should be the same for this
' code to function correctly.
Set rstWrite = dbs.OpenRecordset(sTable, dbOpenDynaset)
Do Until intRow > intMaxRow
' Check row to be sure it is not blank. If so, skip the row
For intCol = 1 To intLastCol
strData = strData & Trim(Nz(wks.Cells(intRow, intCol), ""))
Next
If strData = "" Then
intRow = intRow + 1
Else
intRec = intRec + 1
rstWrite.AddNew
Do Until rstRead.EOF
' Loop through the list of fields, processing them one at a time.
' Grab the field name to simplify code and improve performance.
strCurrFld = Nz(rstRead!AccessField, "")
intCol = rstRead!OrdinalPosition
' Make sure that text fields truncate data at prescribed limits.
' Users may not enter supply more text than the fields can contain.
If dbs.TableDefs(sTable).Fields(strCurrFld).Type = dbText Then
intLen = dbs.TableDefs(sTable).Fields(strCurrFld).Size
varValue = Left(Nz(wks.Cells(intRow, intCol), ""), intLen)
Else
varValue = wks.Cells(intRow, intCol)
End If
' The database schema requires that empty fields contain NULL, not
' the empty string.
If varValue = "" Then varValue = Null
' Handle date columns. Sometimes Excel doesn't format them as dates
If InStr(1, strCurrFld, "Date") > 0 Then
If Not IsDate(varValue) Then
If IsNumeric(varValue) Then
On Error Resume Next
varValue = CDate(varValue)
If err.Number <> 0 Then
' Can't figure out the date. Set to null
varValue = Null
err.Clear
End If
On Error GoTo ProcessFileImport_Error
Else
lngErrs = lngErrs + 1
varValue = Null
End If
End If
rstWrite.Fields(strCurrFld) = varValue
Else
' If not a date field, then just write the value to the rst
rstWrite.Fields(strCurrFld) = varValue
End If
rstRead.MoveNext
Loop
If Not rstRead.BOF Then rstRead.MoveFirst
rstWrite.Update
' Reset the variables for processing of the next record.
strData = ""
intRow = intRow + 1
Debug.Print intRow
End If
Loop
Set wks = Nothing
End If
Exit_Here:
' Report results
strMsg = "Total of " & intRow & " records imported."
' Cleanup all objects (resume next on errors)
On Error Resume Next
Set wks = Nothing
wbk.Close True
Set wbk = Nothing
appExcel.Quit
Set appExcel = Nothing
Set rstRead = Nothing
Set rstWrite = Nothing
Set dbs = Nothing
DoCmd.Hourglass False
Exit Function
ProcessFileImport_Error:
MsgBox err.Description, vbExclamation, "Error"
Resume Exit_Here
End Function
|