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.

  • 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!

8.8

access macro experts

Asked by akiles99 in Access Coding/Macros

Hi,

I have an access form which has import records from the excel and do some works like duplicates check after that insert the appropriate records into the table.The manipulations are done in excel only.

But my company doesn't use the excel so it shows error.
But they can import the records from the excel.SO i need an expert to get the records insert into a table after manipulation in the temp_table.Not using the excel.

Only for importing i like to have excel but for other manipulations i need the code to use the temp_table.

Thanks,
akiles Start 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:
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
Attachments:
[+][-]09.17.2008 at 12:43PM PDT, ID: 22502819

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.17.2008 at 01:10PM PDT, ID: 22503096

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.17.2008 at 01:13PM PDT, ID: 22503129

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.17.2008 at 04:50PM PDT, ID: 22505046

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.17.2008 at 05:14PM PDT, ID: 22505318

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

Zone: Access Coding/Macros
Sign Up Now!
Solution Provided By: capricorn1
Participating Experts: 2
Solution Grade: A
 
 
[+][-]09.17.2008 at 08:00PM PDT, ID: 22506703

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.17.2008 at 08:43PM PDT, ID: 22507126

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.18.2008 at 03:56AM PDT, ID: 22509478

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.18.2008 at 08:13AM PDT, ID: 22511849

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