Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

If Recordset Open, Close

VBA for Access 2002:

What's the best way to do this? The two examples below produce Object Variable ir Wirh Block not set, or Runtime 91 errors

' if recordset is open, close
If rs.State = 1 Then rs.Close
If rs.State And adStateOpen Then rs.Close

Thanks in advance for the help...

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Close ADO Recordset If Already Open
I cannot seem to cleanly close a recordset if it is open. It's been causing me major headaches trying to make sure that the recordset is closed before antoher one is opened. This is largely due to error handling and it leaving recordsets open.

So what I did was just have a routine that ran before a recordset was opened, this is:

VB Code:
If aRST1.State = 1 Then       aRST1.Close    End If

For the most part this seems to work. But occasionaly I get the error "3219 - Operation is not allowed in this context" when it issues the close command above.

Any thoughts?


Close Recordset With Open Datareport
I am having a problem with this...

I want to allow the user to view a report, however, I don't want the database to be left open while they are viewing (I have code in place allowing only one connection at a time based on admin status of DB)

I cant find a way to close the recordset and DB connection with the report open and visible. Here is my code:

Private Sub cmdHistory_Click()
Dim datStartDate As String
Dim datEndDate As String
Dim bytReturnDay As Byte
Dim bytReturnMonth As Byte
Dim intReturnYear As Integer
Dim datDateSerial As Date
Dim SQL As String
Dim rsSched As New ADODB.Recordset

frmDateSelection.GetStartTime bytReturnMonth, bytReturnDay, intReturnYear
datStartDate = bytReturnMonth & "/" & bytReturnDay & "/" & intReturnYear

If datStartDate = "0/0/0" Then

Exit Sub
End If

frmDateSelection.GetEndTime bytReturnMonth, bytReturnDay, intReturnYear
datEndDate = bytReturnMonth & "/" & bytReturnDay & "/" & intReturnYear

If datEndDate = "0/0/0" Then

Exit Sub
End If

'###### get all relavant data

SQL = "SELECT * FROM Schedule WHERE ScheduleStartDate >= #" & Format(datStartDate, "mm/dd/yy") & "# AND ScheduleStartDate <= #" & Format(datEndDate, "mm/dd/yy") & "#"
rsSched.Open SQL, Con1, adOpenForwardOnly, adLockReadOnly, adCmdText

If rsSched.EOF Then MsgBox ("EOF")
Set DataReport1.DataSource = rsSched

'###### load report info
With DataReport1.Sections("Details")
.Controls("txtStartTime").DataField = "ScheduleStartDate"
.Controls("txtEndDate").DataField = "ScheduleEndDate"
.Controls("txtWorkOrder").DataField = "WorkOrder"
.Controls("txtProduct").DataField = "Product"
.Controls("txtTest").DataField = "Test"
.Controls("txtContact").DataField = "ResourceID"
End With

DataReport1.Sections("ReportHeader").Controls("lblTitle").Caption = "Report for " & UserName & Chr(13) & Format(datStartDate, "mmm d, YYYY") & " To " & Format(datEndDate, "mmm d, YYYY")

With DataReport1.Sections("PageHeader")
.Controls("lblStartTime").Caption = "Start Date"
.Controls("lblEndDate").Caption = "End Date"
.Controls("lblWorkORder").Caption = "Work Order"
.Controls("lblProduct").Caption = "Product"
.Controls("lblTest").Caption = "Test"
.Controls("lblContact").Caption = "ResourceID"
End With

'###### close and clean-up
' Timer1.Enabled = True
Set rsSched = Nothing

Exit Sub

End Sub

Clone Recordset Or Open/close
Hey all. I've got a grid with checkboxes. When items are selected, the grid is repopulated based on the selection. When the user clicks BACK, they go back a step.

It's a 3 step process (i.e. select1 -> new rs -> select2 -> new rs -> final screen) so it shows a total of 3 different recordsets in the grid. When at the 3rd level, "back" takes u to the 2nd level and from there, "back" takes u back to the beginning.

I'm wondering if, for the back track, is it better to clone the recordsets (the ones for level1 and level2) and repopulate the grid with the clones, or to close and reopen them on the click?

Error With Open And Close Recordset
I always have a problem with open and close recordset. Can anyone help me fix this.....


' Look up the employee yg nak approve.
sqlStr = "select * from tblLeaveApp where ApprEmpNo = '" & ndEmpNo & "' AND " & "ApprStatus ='" & ndWaiting & "' AND "
sqlStr = sqlStr & "ApprStatus ='" & ndWaiting & "' AND "
sqlStr = sqlStr & "Date_App ='" & ndApplyDate & "'"
myRecSet.Open sqlStr, , adOpenStatic, adLockOptimistic

Do While Not myRecSet.EOF

'sqlStr = "SELECT COUNT (*) FROM tblMLogin WHERE " & _
' "UName='" & ndUser & "' AND " & _
' "Pword='" & txbPassword.Text & "'"

ndStatusA = myRecSet("ApprStatus")
ndStatusA = Trim(ndStatusA)
ndStatusR = myRecSet("RecStatus")
ndStatusR = Trim(ndStatusR)
'ndListEmp = empno org yg apply
ndListEmp = myRecSet("EmpNo")
ndListEmp = Trim(ndListEmp)

''''ubah ni
If IsNull(ndStatusA) Then

MsgBox "This Application Did Not Been Recommended Yet and You Cannot Approve It"
Exit Sub

ElseIf ndStatusA = ndWaiting Then

'Call serList
Call ViewList


pbsaveProgress.Visible = False
pbsaveProgress.Align = vbAlignBottom
pbsaveProgress.Min = 0
pbsaveProgress.Max = 100

tmrsaveTimer.Interval = 100
tmrsaveTimer.Enabled = False


'''die tak hide frm3 why?
MsgBox "No List to Approve"

End If


'''die tak hide frm3 why?
'MsgBox "No List to Approve"
myRecSet.MoveNext '--->it give an error here it says operation is not allwed when object is closed


ADO Recordset Stuck Open - Will Not Close
I have an ADO recordset on an Access database that when open will not close and seems to be stuck in an update state.


aRST2.Open "categories", adata1, adOpenKeyset, adLockPessimistic, adCmdTableDirect

'locate category id, if it is not there then add it
aRST2.Find "category_id='" & scategoryid & " '", , adSearchForward, 1

If aRST2.EOF Then
aRST2.Fields("category_id").Value = scategoryid
aRST2.Fields("category_desc").Value = scategorydesc
End If

aRST2.close (here it issues close but does not actually close, it stays open).

If I issue another aRST2.close I get the error "Run-time error 3219 - Operation is not alowed in this context".

The only way to close is to issue aRST2.CancelUpdate, then .close.

Any thoughts?


Explanation Needed (on Open And Close Recordset)
is opening and closing the
ADODB.recordset and

for every action(a button click that trigger manipulation to the database) is advisable?

i mean everytime when you want to manipulate or relate to the database , everytime you gotta set up the connection and recordset again and again ..... Wouldn't that slow down the process?


Close Recordset Or Close Connection?
I have a recordset and connection I open up, and then I have another recordset from a different table I want to open. Do I need to close the previous connection or recordset? I saw this somewhere but I can't remember. Thanks!

Heres my code so far. You can see at the bottom my feeble attempt at opening a second recordset from a different table.

Option Explicit
Dim Ordernumber As String

Private Sub cmdFind_Click()
Ordernumber = txtOrdernumber.Text

'' Connection to ODBC Start

lblStatus.Caption = "Connecting to MAS90 ODBC"

Dim Mas90 As ADODB.Connection
Dim rstMyrecset As ADODB.Recordset
Dim cmdMyrecset As ADODB.Command
Dim rstmyrecset2 As ADODB.Recordset
Dim cmdmyrecset2 As ADODB.Command
Dim strResults As String
Dim strResults2 As String

Set Mas90 = New ADODB.Connection
Mas90.ConnectionString = "dsn=sotamas90"
lblStatus.Caption = "Connection Successful."

'' Connection to ODBC End

Set cmdMyrecset = New ADODB.Command
cmdMyrecset.ActiveConnection = Mas90
cmdMyrecset.CommandText = "SELECT SalesOrderNumber, LinkToFirstDetailRecord FROM SO1_SOEntryHeader"
Set rstMyrecset = cmdMyrecset.Execute

rstMyrecset.Find "SalesOrderNumber LIKE '" & Ordernumber & "'", 1, adSearchForward

strResults = rstMyrecset.Fields.Item("SalesOrderNumber").Value
txtResults.Text = strResults

strResults2 = rstMyrecset.Fields.Item("LinkToFirstDetailRecord").Value
txtResults2.Text = strResults2

Set cmdmyrecset2 = New ADODB.Command
cmdMyrecset.ActiveConnection = Mas90
cmdMyrecset.CommandText = "SELECT LinkToPrevLine FROM SO2_SOEntryDetailLine"
Set rstmyrecset2 = cmdmyrecset2.Execute

End Sub

Should I Have 100s Of Winsock Connections Open/close.. Or Keep Them Open (hard Q)?
Ive got a server to which many clients connect to.

They each are given a few tasks to complete - which may or may not take a long time to finish, and after each task is done they send back the result.

This has caused massive amounts of problems for me. Right now I keep the connections open all the time. My server listens on one particular winsock control on a particular port to which all clients connect. It then accepts the connection request thru a second array of winsocks, so each client is connected to the server via the array via one connection.

There is generally no problem sending out the tasks thru that single connection/client - but receiving is a problem. The client may need to send back a few hundred kb at a time but since it was completing several tasks at once - it is not always received correctly. My guess is because taskA is sending data thru the connection at the same time as taskB - and the data isnt received right (each task sends its data via a <start> and an <end> string so I know where the start/end of data is and when transmission is over). Its important to note that the tasks are multithreaded (via a 3rd party control)

The data is sent in one line per task. winsock.SendData theResult. But many tasks can complete at around the same time. I thought that VB would wait until the data was completely sent (for one lines code) before moving on... but I dont think this is happening. I even tried adding a DoEvents but to no avail - I still cant receive the data properly. Maybe winsock is 'skipping over' some data - I dont know. (Kinda like when if you 'break' the application winsock does not get incoming data and when you resume it still wont pick it up)

So Ive got 2 options..
1) Somehow figure out how to receive data properly when multiple tasks finish on a client at around the same time and they send data at the same time - basically making the program send the data of a task and not continue until the data has been sent, then send another tasks data.

2) Use many connections. Basically the max # of tasks running at once will be about 10. So the idea is to have another winsock array of 10, each dedicated to one task, and when a task is completed - connect thru the winsock array, send the data, and when the server receives it - it disconnects.

3) A mixture of 1 and 2 - have the 10 winsocks connect to the server and be open at the same time, then I can just send data and receive via a specific winsock array control and there is no problem distinguishing taskA from taskB from taskC on a client, or client from client.

But honestly.. I dont know if its 'bad' to have lots of connections open and close all the time. And I dont know if its 'bad' to have thousands of connections open at the same time either..

What do you guys think?

Open An Excel Worksheet, Close It, Perform Cleanup And Open It Again - Can't Do It
The attached code allows the user to browse for an excel file, open it, and then the code automatically closes it and performs cleanup on the excel objects. I seems to work fine the first time the user opens an excel file, but if the user tries to open an excel file a second time, there is an error. Why is this?

Recordset.Open Or Set Recordset = Connection.Execute()?
Hello to all! Is there any difference with Recordset.Open and Set Recordset = Connection.Execute in executing an SQL query? I just want to know because users of my program sometimes getting the [-2147467259] Timeout expired error. A friend of mine said that Recorset.Open is the correct way in executing an SQL query rather than using Set Recordset = Connection.Execute.

Here's how I code...

Dim Con As New ADODB.Connection
Dim Rs As New ADODB.Recordset

Con.ConnectionString = "Initial Catalog=;Data Source="
Con.CursorLocation = adUseClient

Set Rs = Con.Execute("SQL Query")

-- Hope you understand what I'm saying. I'm quite poor in explaining something in english. Thanks in advance

How Do You Check To See If A Recordset Is Closed When Trying To Open A New Recordset?
I have some code that contains so many recordset open and closes now that I am starting to confuse myself. So I was wondering if I can somehow check to see if a recordset is open already before openign the recordset because when I try my code some times it will work but I have so many ways of opening and closing recordsets that soemtimes it is still open when I want to open it again, cause run-time 3705 error where it tells me I cannot already open my recordset. The thing is the program shuts down right away so I cannot really edit the code without having to load it again.

My 1 line of code below:

rsChild2.Open strSQL, cnParentStation, adOpenStatic, adLockReadOnly

now I want to do soemthign like this:

if rschild2.close is true then
     rsChild2.Open strSQL, cnParentStation, adOpenStatic, adLockReadOnly
    rsChild2.Open strSQL, cnParentStation, adOpenStatic, adLockReadOnly
end if

Any help would be appreciated. Thanks.

Edited by - jjoseph on 11/4/2005 5:52:16 PM

Open A File, Close It, Open Next.
I've got my searching code going now, but I'm looking for a way to tell the program to load each file in a directory, one at a time, search, close it, move on to the next. And I have no clue how to do that. Any ideas?

Thanks in advance.


Open A File, Close It, Open Next.
I've got my searching code going now, but I'm looking for a way to tell the program to load each file in a directory, one at a time, search, close it, move on to the next. And I have no clue how to do that. Any ideas?

Thanks in advance.


Recordset Close
Hi, on my form load event I close all my recordsets and set them equal to nothing. I keep getting an error on one of the closes...just one. It says that "Operation is not allowed in this context". Error #3219. I checked to make sure that it was open before I closed it, and it was. So, what else could be the problem? I'm confused.

Close Recordset?
If an ADO recordset object is declared at the form level, is it necessary to explicitly close it before the form unloads?

Necessary To Close &amp; Set To Nothing... ADO Recordset
If I'm going to set the ADO recordset to nothing, is it necessary to close it before hand?

Set rstAwesomeRecordset = Nothing

Instead of:

Set rstAwesomeRecordset = Nothing


Recordset Close
If you are having a datagrid that are displaying data from a recordset that takes the data from a database.. Can you cut the link between the database and recordset so that the data is still showing in the grid?? and there can be changes done to???

Help To Close This Recordset!
Anybody out there have any easy code to close a recordset? I can't get this to work! My object is a datagrid produced by an SQL query called as a command in my DataEnvironment...

here it is, but how do I close it without exiting the application?

Private Sub cmdFilter_Click()
' run the query, passing the expected parameters.
DataEnvironment1.SearchCompany txtCompany & "%", txtState, txtConfname1, txtLocation
' Ensure the grid is bound to the DataEnvironment
Set DataGrid1.DataSource = DataEnvironment1
DataGrid1.DataMember = "SearchCompany"
End Sub

any ideas for me?

Close Recordset?
If I have a class object I am using for data access and I open a recordset and do blah, blah, blah with it, when I am done with it do I really need to close the recordset?

Can I just set the object to nothing to destroy it and take care of closing the recordset there?

What are problems of setting an object that opened a recordset to nothing without first closing the recordset?

Any thoughts and input would be appreciated!


Recordset: What Happens After Close...?

another short question:

Imagine you're in a a loop where you always open a recordset over and over again:

   querystrB = "SELECT * FROM toestellen WHERE toestellen.merkId = " & rsGelijkeprijzen!merkId
   '(merkID changes during the course of the loop)
   rsGelijkeprijzenB.Open querystrB, cnVeDa, adOpenStatic, adLockOptimistic
Loop Until (...)

The question I have here is: does the reference to the old recordset remains in memory (or does the content of the recordset remains in memory) when another Sql is executed by opening the new recordset (based on other conditions)?µ

Reason for asking this is that, during the application's performance reduces exponentially in speed....and in the end it is VERY slow cause a rather huge amount of data has to be processed...


I want to check if a dao recordset object or database object is closed before closing it, how?

If <....> then
   set rst = nothing
end if

will setting recordset object = nothing close this object or not? ie. have I to call close method before using nothing


Recordset.close Never Works
What are the problems associated with leaving a recordset connection open? I assume they close when the app is closed, I only ask because I can't seem to close any of mine, I always get the error 'Operation is not allowed when the object is closed' when blatently its open as I've just set it to open to run an insert query(which works)?

Recordset Close Opinions....
Aplogies if this is the wrong forum....

I have several forms which use a lot of disconnected and connected recordsets to gather data for a Crystal report. Everything works fine but I'd like an opinion on this:

I've found that when sending a recordset to CR, if you close it after calling the report you get a blank report. So, the report is called and then the rs is set to nothing. Since there is no recordset collection, what I've done is that whenever a recordset, connected or disconnected is created, I add it to a collection using code like this:

dim myColl as collection
dim rsObj as adodb.recordset
set rsObj = new adodb.recordset
'<rs gets opened>
mycoll.add rsObj
now again that's fine. When the form is closed in the QueryUnload event I have a call to a module sub called KillRecordsets(myColl). It looks like this:

Public Sub killRecordsets(coll As Collection)
Dim x As Integer
Dim obj As Recordset
For x = 1 To coll.Count
If Not coll.Item(x) Is Nothing Then
If TypeOf coll.Item(x) Is Recordset Then 'my standard checking..probably redundant but I do it anyways
Set obj = coll.Item(x) 'exposes the object properties
If obj.State = adStateOpen Then obj.Close
Set obj = Nothing
End If
End If

It seems to close and dstroy all the recordsets that weren't closed in the calling sub. Whaddya think? Does it do the job I need it to do?

When To Close The Connection And Recordset?
I have a form that opens a connection and a recordset (ADO). Initially I use the recordset to populate an MSFlexGrid. While the form is open, the user can click on a row to display all the info for the selected record in some text fields. The user can also add, delete, and update a record.

When should I close the connection and the recordset? Should it be when the form gets unloaded? Should it be after each operation (e.g. update)

Please advice

PS: I should mention that after I manage to get to the point that my form functions the way it should, I will add more forms in my application. These other forms will open other connections and recordsets

Error Hit Close Recordset
I have hit the error attached when i close a recordset. The funny part is, when i step thru the codes, there is no error! only when i run the program that will it hit this error.


Recordset Close Problem
Hi everyone.

I have a multipurpose function that loads and updates textboxes from a database. Here's the code:

Public Function RecordAction(intRecID As Integer, strAction As String)
'Declare connection variable
Dim strConn As String

'Build new connection
Set cn = New ADODB.Connection
strConn = "PROVIDER=sqloledb;DRIVER=SQL Server;SERVER=MYSERVER;" & _

'Open Connection
cn.Open strConn

'Build SQL string
Dim strSQL As String
strSQL = "SELECT * FROM ReportRequest WHERE Id_Num = " & intRecID

'Build new recordset
Set rs = New ADODB.Recordset
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.ActiveConnection = cn
rs.Source = strSQL

Select Case strAction
Case "Find"

'Search for record
If rs.EOF Then
MsgBox "Record was not found."
txtRecID = rs.Fields("Id_Num")
txtDateRequested.Text = rs.Fields("DateRequest") & ""
txtPersonRequesting.Text = rs.Fields("PersonRequest") & ""
txtClient.Text = rs.Fields("Clients") & ""
txtDateRequired.Text = rs.Fields("DateRequired") & ""
txtPurpose.Text = rs.Fields("Purpose") & ""
txtCriteria.Text = rs.Fields("Criteria") & ""
txtDestination.Text = rs.Fields("Destination") & ""
txtReportRanBy.Text = rs.Fields("RanReport") & ""
txtReportReviewedBy.Text = rs.Fields("ReviewReport") & ""
txtReportDate.Text = rs.Fields("RanReportDate") & ""
txtReviewDate.Text = rs.Fields("ReviewReportDate") & ""
txtReportComments.Text = rs.Fields("ReviewComments") & ""
txtDestinationResp.Text = rs.Fields("DestResp") & ""
txtDestDate.Text = rs.Fields("DestRespDate") & ""
txtApprovedBy.Text = rs.Fields("ApprovedBy") & ""
txtDestComments.Text = rs.Fields("ApprovedComments") & ""
End If

Case "Update"

Dim strReportDate As String
Dim strReviewDate As String
Dim strDestRespDate As String

intErr = 0

'date validation
strReportDate = CheckDate(txtReportDate.Text)
strReviewDate = CheckDate(txtReviewDate.Text)
strDestRespDate = CheckDate(txtDestDate.Text)

rs.Fields("RanReport") = txtReportRanBy.Text & ""
rs.Fields("ReviewReport") = txtReportReviewedBy.Text & ""
rs.Fields("ReviewComments") = txtReportComments.Text & ""
rs.Fields("DestResp") = txtDestinationResp.Text & ""
rs.Fields("ApprovedBy") = txtApprovedBy.Text & ""
rs.Fields("ApprovedComments") = txtDestComments.Text & ""

If intErr = 0 Then
'update date fields and corresponding text boxes
rs.Fields("RanReportDate") = strReportDate
txtReportDate.Text = strReportDate

rs.Fields("ReviewReportDate") = strReviewDate
txtReviewDate.Text = strReviewDate

rs.Fields("DestRespDate") = strDestRespDate
txtDestDate.Text = strDestRespDate

Call MsgBox("Record Successfully Updated", , "Success")

Call MsgBox("Update Failed", vbCritical, "Update Failed")
End If

End Select

Set rs = Nothing
Set cn = Nothing

End Function

When the lines highlited in bold happen I get this error:

"Operation is not allowed in this context." and it points to the rs.Close. Any ideas?

Close Recordset Problem -
I've got a recordset - rs2, which I use to populate a form, then close after form gets populated. I use the same recordset variable in a couple other places for saving changes etc. I'm running into this problem in a couple of places where I have code to make sure the recordset is closed.

VB Code:
If rs2.State = adStateOpen Then rs2.Close

I keep getting the error - operation is not allowed in this context. rs2 shows as open (1), so the code goes to rs2.Close, that's where I get the error.

Anyone know why this would happen?


Difference Between Close And Nothing...for ADO Recordset
hi all,

can anyone explain me what exactly happens in the system..when a ADO recordset is ....
i) closed
ii) Ado reordset is set to Nothing
and what r the advantages / disadvantages in using the above two methods...

ThanX in advance

Where To Place Recordset.close
I woke up to find my site crashed today, Microsoftr Access 'Out of System Resources' error.

Seems like the most likely cause is an unclosed recordset.

I have gone over my code and it seems like every has a corresponding:

set rs = Nothing

My question is, does the placement in my ASP file make a difference to anything? I have a, then several IF's that use the data, then the rs.close. Could having my rs.close way down at the bottom be causing it to not work? The question in a simpler form: If a recordset is closed, can code after the close still access the recordset data?

Another question, do I need to put a 'strSQL.close' after the following statement :

strSQL_NEW="UPDATE [qOrders] Set [status]='Completed', [TrackingNumber]='"&PP_Txn_ID&"', [carrier]='Digital' WHERE [OrderID]="&PP_Item_Name
'Call up the customer order info:


Recordset Wont Close
hi, im using an access database through the dataenviroment with JET

1. I opened the record
2. bound some textboxes to the data
3. edit the data
4. called cancel, cancelbach and even cancelupdate
5. CLOSED the recordset

the recordset seemed to close but when i call .open I get the error "(-2147217915) Object was open." What is going on here because I closed the recordset and removed all binds to it.

it seemes even after the datamember and datafield from the textboxes were set to "" they were still bound to the recordset. The problem is with the textboxes unbinding from the recordset.

Edited by - shadow2xp on 5/2/2006 1:37:53 PM

Open DAO Recordset Without Using A Recordset Object
In order to use a certain password-protected ODBC connection, I first run a Pass-Through query against one of the tables.  Once the Pass-Through query is run I can use linked tables in my Access db without concerning myself with the password protection.

I've set up the Pass-Through query (we'll call it ConnectionQ) in my Access db and call it like this:

dbDBase.OpenRecordset "ConnectionQ"

Where does that recordset go?  Do I need to worry about a recordset object that might be floating around in my stack space?  or does it get created and destroyed all in one operation?  It is a SELECT query as I'm unable to run any action queries against the ODBC db.

Recordset.Close Cause Out Of Context Error '3219'. What Gives?
I am using a recordset during the life of a form.
In the Form_Unload function, I have the check to prompt to save for changes, etc.

I call a SaveEvent sub, that calls Recordset.Update

When I do a Recordset.Close in the Unload call, it gives me an out of Context error.
Why is this? What did I do wrong?
Other co-workers were able to call Close from their Unload sub.

Thanks for the help

Close Then Re-open App
I am trying to find a solution that will close and then re-open a vb app if it is idle for more than 30 mins
The reason is because I was told that vb apps don't release memory so I want to sort of "auto release or refresh the memory" any ideas?

Open Close
When i user this code to open a file:

Open FName For Input As #1
Input #1, Data
Close #1
Edit1.Text = Data
It opens the first line or up to the next ','. What is the correct method for opening a file?

Open/close Cd-rom
how do you open/close the cd-rom in vb5?

Close An Open Exe From A Different Exe
How do I close an open Exe from another Exe?
Once I close this Exe I want to delete this Exe from another Exe, Please let me know as to how can I do this?

How Do You Close An Open App?
If I want to close something with code, and I know its running, like ms word or something, how would I go about doing that?

Open/Close Cd Rom can i open and close the cdrom using a command button?

Close And Open Again ...
how i can close my program and open it again ...

On Close Open App
how do i do something like on close of application or on error open "shell code here"

How To Open/close CD-ROM?

Does anybody know how to open/close CD-ROM?

I'm really a amatuer so..............



Close Exe That's Open?
I need to close an Exe that's already running. I know the window title, and the name of the exe. Thanks for any help!

If Open Then How To Close
In my code I'm creating a log file of some of the events I'm trying to track. Every now and then when the program checks to see if the log file exists it flags that its open then immediately exist the sub. Meanwhile it missed an entry. The error I receive tells me that the log file is open when checking for the existance.

What am I missing:


Public strChecker As String

'create migration logs
Public Sub LogName()

Dim strLog As String
Dim Location As String

Location = App.Path & ""
strLog = Location & strLogName & ".log"

strChecker = strLog
If intTest <> 0 Then
Open strLog For Append As #1
Open strLog For Output As #1
End If

'the information for the log goes below

end sub

''if intTest=0, then there is no file to replace. Anything else means it exists.
Public Sub FileExists()

intTest = Not (Dir(strChecker) = "")
strChecker = ""

End Sub

If the log file was left open for some reason intTest returns a -1 indicating the fileexists, thats good, but when it returns to the if then above and tries to append the file it jumps out.

Is there a way to check to see if "c:crap.log" is open before appending then close it.


Close All IEs Open
Anyone have a code to closes all instances of IE open,not just the active one?


CD Open And Close
does anyone know how you can open and close the cd-rom drive with visual basic?

Close Connection, Cancel Recordset Going To An Informix Database
I have a Vb program that creates an SQL Statement. It then Takes that sql statement and tries to execute it.
it looks like this

Cn is the connection.
strSql = "SELECT tabname FROM informix.systables inf WHERE inf.tabid > '99' " & _
" AND tabname = 'claims' " & _
" OR tabname = 'policy_master' " & _
" OR tabname = 'premium' " & _
" ORDER BY tabname"
rs.CursorType = adOpenStatic
rs.LockType = adLockOptimistic
rs.Open strSql, cn, , , adAsyncExecute
intTimer = Timer
Do While CBool(rs.State And adStateExecuting)
If Timer >= intTimer + 10 Then
If MsgBox( _
"Still trying to connect -- keep waiting?", _
vbYesNo) = vbNo Then
TimedOut = True
MsgBox "Startup Canceled!"

Exit Sub
End If
End If
If Timer >= intTimer + 30 Then
TimedOut = True
MsgBox "Startup Canceled!"
Exit Sub
End If

When the database is having problems it will ask if you want to contiune. If the user says no then it will close the recordset and Cancel it. However on the cancel it sits there and doesn't do anything. If I try to do cn.Close it also just sits there. I am using and ODBC connection. This only happens at certain times not all the time. Any help would be great if you have any questions for me please let me know.

? On Open / Close Files In VB
I have a text file (see below) that I only care for "Port x/xx" at the end of each line. This is the output of a Cisco switch from issuing the "show logging buffer 1023" command and the output is being captured to a text file.
What is the best way to remove all the duplicated "Port x/xx" on each line?
Based on my limited VB experience, I can only think of opening 2 files within VB. 1) being input and the other being output. Read the text file one line at a time and using a string command to keep only "Port x/xx" and write that info into a second file. In the end, I will have the second file that contains all the "Port x/xx" with no similar entries.
I notice using open/close files in VB is time consuming imagine there are 25 of such logs I have to go through. Are there different or quicker methods to get this done?

Thanks in Advance,

Log file starts here
2004 Mar 09 09:34:05 %PAGP-5-PORTTOSTP:Port 3/14 joined bridge port 3/14
2004 Mar 09 09:34:25 %PAGP-5-PORTFROMSTP:Port 3/14 left bridge port 3/14
2004 Mar 09 09:34:33 %PAGP-5-PORTTOSTP:Port 3/14 joined bridge port 3/14
2004 Mar 09 10:02:38 %CDP-4-DUPLEXMISMATCH:Full/half duplex mismatch detected on port 3/11
2004 Mar 09 10:03:46 %PAGP-5-PORTTOSTP:Port 2/28 joined bridge port 2/28
2004 Mar 09 10:32:46 %PAGP-5-PORTFROMSTP:Port 3/22 left bridge port 3/22
2004 Mar 09 10:32:54 %PAGP-5-PORTTOSTP:Port 3/22 joined bridge port 3/22
2004 Mar 09 10:34:38 %CDP-4-DUPLEXMISMATCH:Full/half duplex mismatch detected on port 3/11
2004 Mar 09 10:37:50 %PAGP-5-PORTFROMSTP:Port 3/22 left bridge port 3/22
2004 Mar 09 10:37:59 %PAGP-5-PORTTOSTP:Port 3/22 joined bridge port 3/22
2004 Mar 09 10:42:10 %PAGP-5-PORTFROMSTP:Port 3/22 left bridge port 3/22
2004 Mar 09 10:42:18 %PAGP-5-PORTTOSTP:Port 3/22 joined bridge port 3/22
2004 Mar 09 11:06:38 %CDP-4-DUPLEXMISMATCH:Full/half duplex mismatch detected on port 3/11
2004 Mar 09 11:23:33 %PAGP-5-PORTFROMSTP:Port 3/32 left bridge port 3/32
2004 Mar 09 11:24:04 %PAGP-5-PORTTOSTP:Port 3/32 joined bridge port 3/32
2004 Mar 09 11:24:44 %PAGP-5-PORTFROMSTP:Port 3/32 left bridge port 3/32
2004 Mar 09 11:25:18 %PAGP-5-PORTTOSTP:Port 3/32 joined bridge port 3/32
2004 Mar 09 11:26:28 %PAGP-5-PORTFROMSTP:Port 3/32 left bridge port 3/32
2004 Mar 09 11:26:34 %PAGP-5-PORTTOSTP:Port 3/32 joined bridge port 3/32
2004 Mar 09 11:38:38 %CDP-4-DUPLEXMISMATCH:Full/half duplex mismatch detected on port 3/11
2004 Mar 09 12:10:38 %CDP-4-DUPLEXMISMATCH:Full/half duplex mismatch detected on port 3/11
2004 Mar 09 12:42:38 %CDP-4-DUPLEXMISMATCH:Full/half duplex mismatch detected on port 3/11
Log file ends here

Open/Close Program
I'm trying to write a program that will be able to open a file, apply values from the file in an array, close that file. If I try to open another file and apply a different number of values to the same array (even if I redimension it first), I get a 'Subscript out of range' error.

I think the best way around this error is if I can simply restart the program.
Is there a way to run a separate vb program that will close the current program, and re-open it?

Open And Close Access
Sounds simple enough, but I'm not quite sure where to start. I used the tutorial for opening and closing Excel, but it looks like the commands are different and after a lot of searching, I still cannot find a code example of how to open and close Access from VB. If someone could share a code snippet, I'd really appreciate it!

Copyright 2005-08, All rights reserved