Solved

where to put the ADO cmds..FormLoad?

Posted on 2004-04-06
4
194 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

707 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