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.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

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!

7.8

Need assistance modifying an Excel macro that updates an Access database

Asked by akiles99 in Microsoft Excel Spreadsheet Software, Microsoft Access Database

Hi,

I have an excel file that has to be modified and insert to table into access database.Then the excel records has to be checked with the access table if the records match overwrite it else add the new records.

Student information will be imported into the Students table. You will need to get a unique list of students from the file based on the StudentID. (There are 533 infractions, but only 19 students. These 19 names and information will be added to the Students table. If a student is already in the table (based on the StudentID number, that student isn't imported.)

Infraction information is appended to the Offenses table. Before the import, it will check to see if infractions with the same School Name and School year are already in the table. If these records exist, the user will get a message.("You already have records for [SchoolName] for the [SchoolYear]school year. Do you want to remove these records and replace them with records from your import?"

If the answer is yes, records for that school and school year are deleted from the table and the records from the Excel file are appended. If the answer is no, the process stops.

Thanks,
akilesStart Free Trial
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
Attachments:
[+][-]09.09.2008 at 01:51AM PDT, ID: 22425281

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 02:08AM PDT, ID: 22425363

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 02:09AM PDT, ID: 22425367

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 02:12AM PDT, ID: 22425376

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Excel Spreadsheet Software, Microsoft Access Database
Sign Up Now!
Solution Provided By: Psychotec
Participating Experts: 2
Solution Grade: A
 
 
[+][-]09.09.2008 at 02:37AM PDT, ID: 22425504

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 02:41AM PDT, ID: 22425521

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 02:42AM PDT, ID: 22425523

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 03:02AM PDT, ID: 22425630

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 03:04AM PDT, ID: 22425640

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 03:46AM PDT, ID: 22425883

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 04:06AM PDT, ID: 22426017

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 04:23AM PDT, ID: 22426131

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 04:27AM PDT, ID: 22426166

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 04:39AM PDT, ID: 22426259

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 05:00AM PDT, ID: 22426436

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 05:03AM PDT, ID: 22426468

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 05:13AM PDT, ID: 22426552

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 05:43AM PDT, ID: 22426791

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 05:47AM PDT, ID: 22426818

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 05:54AM PDT, ID: 22426869

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 06:00AM PDT, ID: 22426910

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 06:08AM PDT, ID: 22426955

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 06:09AM PDT, ID: 22426966

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 06:15AM PDT, ID: 22427007

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 06:20AM PDT, ID: 22427043

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 06:25AM PDT, ID: 22427065

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 06:28AM PDT, ID: 22427086

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 06:37AM PDT, ID: 22427166

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 06:45AM PDT, ID: 22427252

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 06:48AM PDT, ID: 22427281

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 06:51AM PDT, ID: 22427306

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 06:54AM PDT, ID: 22427345

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 06:56AM PDT, ID: 22427367

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 07:32AM PDT, ID: 22427769

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.09.2008 at 12:01PM PDT, ID: 22430870

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628