Solved

where to put the ADO cmds..FormLoad?

Posted on 2004-04-06
4
190 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
  • 2
4 Comments
 
LVL 29

Expert Comment

by:leonstryker
Comment Utility
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
Comment Utility
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
Comment Utility
One correction:
rsBC.Open theBCsql, strConnect, adOpenForwardOnly, adLockPessimistic

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

S

0
 
LVL 7

Expert Comment

by:ScrptMasta
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now