Advertisement
Advertisement
| 09.17.2008 at 11:26AM PDT, ID: 23739809 |
|
[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: |
Option Compare Database
Option Explicit
Private Sub btn_ImportOffenses_Click()
Dim xl As Excel.Application
Dim fileName As String
Set xl = New Excel.Application
fileName = xl.GetOpenFilename("Excel Files (*.xls), *.xls", , "Select the 'excel' File")
If fileName = "False" Then Exit Sub
CurrentDb.Execute "Delete * from tblDTMasterExport"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
"tblDTMasterExport", fileName, True
If (MsgBox("Do you want to import all records?", vbQuestion + vbYesNo)) = vbNo Then
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryDTMasterOffenses_NotIn"
DoCmd.SetWarnings True
Else
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryDTMasterOffenses"
DoCmd.SetWarnings True
End If
'
MsgBox "Successfully Completed"
xl.Quit
Set xl = Nothing
End Sub
Private Sub btn_ImportStudents_Click()
'Open Workbook
Dim xl As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim fileName As String
Set xl = New Excel.Application
fileName = xl.GetOpenFilename("Excel Files (*.xls), *.xls", , "Select the 'excel' File")
If fileName = "False" Then GoTo Bye
Set wb = xl.Workbooks.Open(fileName)
Set ws = wb.ActiveSheet
'Delete Dupes from spreadsheet
Dim row As Integer
Dim numRows As Integer
Dim col As Byte
Dim numCols As Byte
Dim currentStudentId As Long
Dim previousStudentId As Long
Dim recordNum As Integer
numRows = ws.UsedRange.Rows.Count
recordNum = 1
For row = 2 To numRows
SysCmd acSysCmdSetStatus, "Deleting Duplicates - Evaluating Record " & recordNum & " of " & numRows - 1
currentStudentId = ws.Range("N" & row).Value
If currentStudentId = 0 Then
Exit For
End If
If currentStudentId = previousStudentId Then
Rows(row).Delete
row = row - 1
Else
previousStudentId = currentStudentId
End If
recordNum = recordNum + 1
Next
'wb.Save
numRows = ws.UsedRange.Rows.Count
numCols = ws.UsedRange.Columns.Count
'Insert remaining rows into Access table
On Error GoTo Oops
Dim rs As ADODB.Recordset
Dim rsIdExists As DAO.Recordset
Dim sql As String
Set rs = New ADODB.Recordset
SysCmd acSysCmdSetStatus, "Opening table ..."
rs.Open "students", Access.CurrentProject.Connection, adOpenForwardOnly, adLockOptimistic
For row = 2 To numRows
SysCmd acSysCmdSetStatus, "Inserting record " & row - 1 & " of " & numRows - 1
currentStudentId = ws.Range("N" & row).Value
sql = "SELECT StudentID FROM students WHERE StudentID = " & currentStudentId
Set rsIdExists = CurrentDb.OpenRecordset(sql)
If rsIdExists.RecordCount = 0 Then
rs.AddNew
For col = 2 To numCols
rs.Fields(ws.Cells(1, col).Value) = ws.Cells(row, col)
Next
rs.Update
End If
rsIdExists.Close
Next
rs.Close
MsgBox "Successfully Completed"
Bye:
On Error Resume Next
SysCmd acSysCmdClearStatus
Set rsIdExists = Nothing
Set rs = Nothing
Set ws = Nothing
wb.Close
Set wb = Nothing
xl.Quit
Set xl = Nothing
Exit Sub
Oops:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Bye
End Sub
|