Results 1 to 8 of 8

Thread: searching access database

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    18

    searching access database

    Hello,

    I have an access database with 100,000+ records that I need to search through. I only need to work with the records that have a value in the account number field. Right now I have it going down the table and whenever it finds a row with an account number in it, it does the computations. This process only allows a few hundred records to be done every minute. I need to speed this up, but I have no clue how. Any help would really help me out


    Code:
    For i = 1000 To x 'x is number of rows in table
    
        
        
        Adodc1.RecordSource = "SELECT * FROM tSaleTransactions Where cdeTrans='A" & i & "'"
      
        Adodc1.Refresh
      
        If Adodc1.Recordset.Fields("cdeCustCode") <> Empty Then
    'does computations
    Last edited by mooe; Jun 1st, 2008 at 08:10 PM.

  2. #2
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: searching access database

    Each SQL call is going to take a long time. Faster would be to ditch the databound controls and go with direct access using ADO. And when I say faster, I mean the entire loop would probably take a few seconds from start to finish.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    18

    Re: searching access database

    I will admit I know almost nothing about coding, but isn't ado what I am using in my code example? If you could point me in the direction I would really appreciate it.

    Thanks!

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: searching access database

    Well I probably wouldn't use that ADODC because it carries a lot of baggage with it. I'm not saying to avoid it, just avoid it for this operation. For example:
    Code:
    Dim rsCompute As ADODB.Recordset
    
    Set rsCompute = New ADODB.Recordset
    With rsCompute
        .Open "SELECT only the fields you need FROM tSaleTransactions", _
              Adodc1.Recordset.ActiveConnection, _
              adOpenForwardOnly, adLockReadOnly, adCmdText
        .MoveFirst
        Do Until .EOF
            If Not IsNull(!cdeCustCode.Value) Then
                'Do computations.
            End If
            .MoveNext
        Loop
        .Close
    End With
    Set rsCompute = Nothing
    Notes:
    • You might want a WHERE clause in the SQL statement if there are values below A1000 that you want to exclude.
    • You might want another LockType if you are updating values as part of your "computations."
    • You might need to add .Update before .MoveNext if you change field values as part of your "computations."
    • You might not want to use Not IsNull() depending on how your "no value" values are stored. For empty String values you should probably use Len() > 0 as a test instead if you didn't store NULLs.

    This might be off a little from what you want, but it should be close.
    Last edited by dilettante; Jun 1st, 2008 at 08:48 PM.

  5. #5
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: searching access database

    Quote Originally Posted by mooe
    isn't ado what I am using in my code example?
    Well, you aren't using ADO; the databound control is. If you use ADO directly you'll greatly improve your control over what's going on, which will allow you to greatly speed up execution.

    ETA: dillettante showed you the basic idea. You can also edit data inside the loop. Post any specific questions you have.
    Last edited by Ellis Dee; Jun 1st, 2008 at 08:48 PM.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    18

    Re: searching access database

    Edit: Realized my mistake. I'm an idiot.
    Last edited by mooe; Jun 1st, 2008 at 09:24 PM.

  7. #7
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: searching access database

    No, you're just not used to doing this stuff all the time.

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: searching access database

    Thread moved to Database Development forum (the "VB6" forum is meant for questions which don't fit in more specific forums)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width