Solved

where to put the ADO cmds..FormLoad?

Posted on 2004-04-06
4
193 Views
Last Modified: 2012-05-04

I have a Timer that will be running a query to see if any records need to be processed
Should I put the whole ado connection stuff in the timer, or should I put the DIMming in the Formload, and Closing in the Unload?

Timer1_Timer()
    Dim cnBC As New ADODB.Connection
    Dim rsBC As New ADODB.Recordset
    Dim strConnect As String
    Dim tsql As String
   
 
strConnect = "Provider= Microsoft.Jet.OLEDB.4.0; Data Source = d:\db\data.mdb; Persist Security Info = False"
tsql = "Select * from AAA WHERE Processed = 'Y' "
rsBC.Open theBCsql, strConnect, adOpenForwardOnly, adLockPessimistic

If NOT rsBC.EOF Then
   StartProcess
End if    

rsBC.Close
Set rsBC = Nothing

End Sub
0
Comment
Question by:williamsF1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 29

Expert Comment

by:leonstryker
ID: 10768989
The connection should be declared Global since you will probably will be reusing it.  The rest I would put in behind the form itself.

Leon
0
 
LVL 19

Accepted Solution

by:
Shauli earned 50 total points
ID: 10768992
In form declaration:
    Dim cnBC As New ADODB.Connection
    Dim rsBC As New ADODB.Recordset
    Dim strConnect As String
    Dim tsql As String

In Form_Load: 'To open a connection
cnBC .Open "Provider= Microsoft.Jet.OLEDB.4.0; Data Source = d:\db\data.mdb; Persist Security Info = False"

In Timer: 'run your recordset
rsBC.Open theBCsql, strConnect, adOpenForwardOnly, adLockPessimistic

If NOT rsBC.EOF Then
   StartProcess
End if    

rsBC.Close
Set rsBC = Nothing


In Form_Query_UnLoad: 'to close the connection
cnBC .Close

S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10769012
One correction:
rsBC.Open theBCsql, strConnect, adOpenForwardOnly, adLockPessimistic

Should be:
rsBC.Open theBCsql, cnBC, adOpenForwardOnly, adLockPessimistic
                              ^^^

S

0
 
LVL 7

Expert Comment

by:ScrptMasta
ID: 10769500
Just as a suggestion, consider switching to SQL/MSDE. This way you can load a stored procedure in the database itself and not have to worry about constantly checking to see with the sub you have up there. SQL will automatically do what it supposed to when trigger takes place.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question