Advertisement

06.03.2008 at 05:36AM PDT, ID: 23452865
[x]
Attachment Details

Access - speeding up VBA code

Asked by davecocks in Access Coding/Macros, VB Script

Tags: Microsoft, Access, 2003

My question relates to whether there is any way of improving the attached code as it seems to take a long time to operate.

The code is translating (with a few tweeks) an imported txt or csv file from one Access table (IMPORT) into another (Data_intermediate).

I'm running it from a button click:

Private Sub Run_Import_Click()

    DoCmd.Hourglass True
   
Call TransposeImportTbl

    DoCmd.Hourglass False
    DoCmd.Beep

End Sub

and I'm referencing values from combo boxes on a form - Is that a likely cause?

There are usually a lot of records generated (i.e. in excess of 5000) but all other operations with SQL - for example updating - with many more records do not take so long.

Any thoughts?
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:
Public Sub TransposeImportTbl()
Dim rs As DAO.Recordset, rs1 As DAO.Recordset
Dim i As Integer, j As Integer, fldArr()
 
On Error GoTo Err_out
 
'These variables take values off the Form
Dim Local_ID As String
Local_ID = Forms![Bulk Data Import Form]!LocationID_combo.Value
Dim File_ID As String
File_ID = Forms![Bulk Data Import Form]!FileID_combo.Value
Dim DataGroup_ID As String
DataGroup_ID = Forms![Bulk Data Import Form]!DataGroupID_combo.Value
 
Set rs = CurrentDb.OpenRecordset("IMPORT")  
Set rs1 = CurrentDb.OpenRecordset("Data_Intermediate") 
 
If rs.EOF Or rs.BOF Then
    MsgBox "no records"
    Exit Sub
End If
rs.MoveFirst
    For i = 0 To rs.Fields.Count - 1
        ReDim Preserve fldArr(i)
        fldArr(i) = rs.Fields(i).Name
    Next
 
Do Until rs.EOF
    For j = 2 To UBound(fldArr)
        If Not rs(fldArr(j)).Value Then  ' if not null
           With rs1
                .AddNew
                ![Date] = rs("Date")
                !Time = rs("Time")
                ![Data] = rs.Fields(fldArr(j))
                !DeterminantID = rs.Fields(fldArr(j)).Name
                !FileID = File_ID
                !LocationID = Local_ID
                !DataGroupID = DataGroup_ID
                .Update
            End With
            Else
        End If
    Next
    rs.MoveNext
Loop
 
Err_out:
Exit Sub
 
End Sub
 
Loading Advertisement...
 
[+][-]06.03.2008 at 05:48AM PDT, ID: 21699786

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.03.2008 at 06:04AM PDT, ID: 21699905

View this solution now by starting your 7-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: Access Coding/Macros, VB Script
Tags: Microsoft, Access, 2003
Sign Up Now!
Solution Provided By: capricorn1
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.03.2008 at 07:14AM PDT, ID: 21700633

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.03.2008 at 07:57AM PDT, ID: 21701015

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 03:38AM PDT, ID: 21708584

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628